如何在剧情标题或标签中加下划线? (GGPLOT2) [英] How to underline text in a plot title or label? (ggplot2)
问题描述
请原谅我的无知,如果这是一个简单的问题,但我似乎无法弄清楚如何强调剧情标题的任何部分。我使用 ggplot2
。
我能找到的最好的是
underline-text-in-a-barplot-in-r>使用plotmath并提供了一种解决方法,但它没有帮助
ggplot(df,aes(x = x,y = y))+ geom_point()+
ggtitle(表达式(粘贴(哦,我多么希望,下划线(下划线))))
或者,BondedDust在注释中指出,您可以完全避免 paste()
调用,但要注意 for
:
ggplot(df,aes(x = x,y = y)) + geom_point()+
ggtitle(表达式(哦〜how〜I〜wish〜'for'〜underline(underlining)))
或者另一种方法,baptiste提出的不使用表达式
, paste() code>,或者多个代字符:
ggplot(df ,aes(x = x,y = y))+ geom_point()+
pre>
ggtitle(〜哦,我希望如何*下划线(下划线))
Please pardon my ignorance if this is a simple question, but I can't seem to figure out how to underline any part of a plot title. I'm using
ggplot2
.The best I could find was annotate("segment") done by hand, and I have created a toy plot to illustrate its method.
df <- data.frame(x = 1:10, y = 1:10) rngx <- 0.5 * range(df$x)[2] # store mid-point of plot based on x-axis value rngy <- 0.5 * range(df$y)[2] # stores mid-point of y-axis for use in ggplot ggplot(df, aes(x = x, y = y)) + geom_point() + ggtitle("Oh how I wish for ..." ) + ggplot2::annotate("text", x = rngx, y = max(df$y) + 1, label = "underlining!", color = "red") + # create underline: ggplot2::annotate("segment", x = rngx-0.8, xend = rngx + 0.8, y= 10.1, yend=10.1)
uses bquote(underline() with base R
pertains to lines over and under nodes on a graph
uses plotmath and offers a workaround, but it didn't help
解决方案Try this:
ggplot(df, aes(x = x, y = y)) + geom_point() + ggtitle(expression(paste("Oh how I wish for ", underline(underlining))))
Alternatively, as BondedDust points out in the comments, you can avoid the
paste()
call entirely, but watch out for thefor
:ggplot(df, aes(x = x, y = y)) + geom_point() + ggtitle(expression(Oh~how~I~wish~'for'~underline(underlining)))
Or another, even shorter approach suggested by baptiste that doesn't use
expression
,paste()
, or the many tildes:ggplot(df, aes(x = x, y = y)) + geom_point() + ggtitle(~"Oh how I wish for "*underline(underlining))
这篇关于如何在剧情标题或标签中加下划线? (GGPLOT2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!