在批注中使用不同的字体样式(ggplot2) [英] Using different font styles in annotate (ggplot2)
本文介绍了在批注中使用不同的字体样式(ggplot2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的代码生成带有一些注释的简单图表:
require(ggplot2);数据(mtcars)
ggplot(mtcars,aes(x = wt,y = mpg))+
geom_point()+
注释(text,x = 4,y = 25, label =这应该是bold'\
and这不是,
color =red)+
geom_vline(xintercept = 3.2,color =red)
在那张图表上我想将粗体字应用于文本注释中词组的第一部分: / p>
但我希望文本的其余部分在字体和样式方面保持不变。 b $ b
解决方案使用 plotmath 语法如何使用
parse = TRUE
: ggplot(mtcars,aes(x = wt,y = mpg))+
geom_point()+
an notate(text,x = 4,y = 25,
label ='atop(bold(This should be bold),this should not)',
color =red ,parse = TRUE)+
geom_vline(xintercept = 3.2,color =red)
I'm using the code below to generate a simple chart with some annotations:
require(ggplot2); data(mtcars)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
annotate("text", x = 4, y = 25, label = "This should be bold\nand this not",
colour = "red") +
geom_vline(xintercept = 3.2, colour = "red")
On that chart I would like to apply bold font to the first part of the phrase in the text annotation:
This should be bold
but the I wish for the remaining part of the text to remain unaltered with respect to the font face and style.
解决方案
How about using plotmath syntax with parse = TRUE
:
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
annotate("text", x = 4, y = 25,
label = 'atop(bold("This should be bold"),"this should not")',
colour = "red", parse = TRUE) +
geom_vline(xintercept = 3.2, colour = "red")
这篇关于在批注中使用不同的字体样式(ggplot2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文