我似乎不知道如何在情节标题的任何部分下划线。
我能找到的最好的是 annotate("segment") done by hand ,并且我创建了一个玩具图来说明其方法。
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
最佳答案
试试这个:
ggplot(df, aes(x = x, y = y)) + geom_point() +
ggtitle(expression(paste("Oh how I wish for ", underline(underlining))))
或者,正如 BondedDust 在评论中指出的那样,您可以完全避免 paste()
调用,但要注意 for
:
ggplot(df, aes(x = x, y = y)) + geom_point() +
ggtitle(expression(Oh~how~I~wish~'for'~underline(underlining)))
或者巴蒂斯特建议的另一种更短的方法,不使用表达式
、paste()
或许多波浪号:
ggplot(df, aes(x = x, y = y)) + geom_point() +
ggtitle(~"Oh how I wish for "*underline(underlining))
关于r - 如何在绘图标题或标签中的文本下划线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30470293/