當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R ggplot2 get_alt_text 從繪圖中提取替代文本

該函數返回一個文本,可以在網頁等中用作alt-text。目前它將使用alt標簽,添加+ labs(alt = <...>),或者返回一個空字符串,但將來它可能會嘗試生成一個來自繪圖中存儲的信息的替代文本。

用法

get_alt_text(p, ...)

參數

p

一個 ggplot 對象

...

目前被忽略

文本字符串

例子

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()

# Returns an empty string
get_alt_text(p)
#> [1] ""

# A user provided alt text
p <- p + labs(
  alt = paste("A scatterplot showing the negative correlation between engine",
              "displacement as a function of highway miles per gallon")
)

get_alt_text(p)
#> [1] "A scatterplot showing the negative correlation between engine displacement as a function of highway miles per gallon"

源代碼:R/labels.R

相關用法


注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Extract alt text from a plot。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。