【发布时间】:2021-01-05 17:35:45
【问题描述】:
我正在尝试使用paste() 内的grDevices 中的bold() 和underline() 函数来创建一个注释,该注释具有一个风格化、硬编码的“标题”,其中一个换行符后跟一个可能是一个字符串或更多行,并且正在努力完成它。 (这是在 ShinyApp 中完成的,所以我不能硬编码两个相邻的注释,因为字符串中的行数会根据用户输入而变化。)
library(ggplot2)
library(grDevices)
mydata <- data.frame(Strings = c("This is a list of strings",
"They could be \n one line long",
"Or they could \n be several lines \n long"),
NumberOfLines = c(1, 2, 3))
rowposition <- sample(1:3, 1)
mystring <- mydata$Strings[rowposition]
emptydataframe <- data.frame()
ggplot(emptydataframe) +
geom_blank() +
annotate("text", x = 8, y = -4,
label = paste(bold(underline("Title\n")), mystring),
size = 3)
非常感谢任何帮助。
【问题讨论】:
标签: r ggplot2 annotate plotmath ggtext