如何用乳胶注释()ggplot [英] How to annotate() ggplot with latex
本文介绍了如何用乳胶注释()ggplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 annotate()
将乳胶文本添加到ggplot2图中。使用 expression()
,如 here 为轴标签添加乳胶,似乎不起作用。换句话说:
#使用expression()创建下标文本
p < - ggplot(mpg,aes(x ())+ geom_point()+
scale_x_continuous(表达式(text [下标]))
#但是annotate中的表达式()没有为plot添加任何内容$ b $传递常规文本注释工作正常
p + annotate(text,x = 10,y = 40,label = expression(text [下标]))
# text,x = 10,y = 40,label =foo)
为什么表达式
s与其他ggplot函数不同地处理注释
我可以使用 parse
来解决这个问题。我可以使用 parse
参数,没有表达式
:
p +注释(text ,x = 10,y = 40,label =text [下标],parse = TRUE)
I'd like to add latex text to a ggplot2 plot using annotate()
. Using expression()
, as described here for adding latex to axis labels, does not seem to work. To wit:
# Use expression() to create subscripted text
p <- ggplot(mpg, aes(x=cty, y=hwy)) + geom_point() +
scale_x_continuous(expression(text[subscript]))
# But expression() in annotate adds nothing to the plot
p + annotate("text", x=10, y=40, label=expression(text[subscript]))
# Passing regular text to annotate works fine
p + annotate("text", x=10, y=40, label="foo")
Why are expression
s treated differently by annotate
than by other ggplot functions? And how can I annotate with latex?
解决方案
You can use the parse
argument, without expression
:
p + annotate("text", x=10, y=40, label="text[subscript]", parse=TRUE)
这篇关于如何用乳胶注释()ggplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文