如何解决如何加粗和加下划线ggplot2注释的一部分?
我正在尝试使用bold()
中underline()
中的grDevices
和paste()
函数来创建一个注释,该注释具有带换行符的风格化,硬编码的“标题”然后是一个可能长达一行或更多行的字符串,并且正在努力实现。 (这是在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)
非常感谢您的帮助。
解决方法
使用ggtext
软件包:
library(ggtext)
ggplot(emptydataframe) +
geom_blank() +
annotate("richtext",x = 8,y = -4,label = paste("<b>Title</b><br>",mystring),size = 3)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。