如何在剧情标题或标签中加下划线? (GGPLOT2) [英] How to underline text in a plot title or label? (ggplot2)

查看:211
本文介绍了如何在剧情标题或标签中加下划线? (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()+ 
ggtitle(〜哦,我希望如何*下划线(下划线))
pre>

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 the for:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆