[英]Problem with mathematical expression annotation in ggplot2
我想在ggplot图表中进行以下注释
我正在打这
ggplot(data = data.frame(x = c(0, 70)), aes(x)) +
stat_function(fun = dchisq, args = list(df = 30))+
annotate("text", x = c(7), y = c(0.019),
label = "P(16.791<=chi[70]^{2}<46.979)==0.95",parse = TRUE , size=4 , fontface="bold")
并得到以下错误
Error in parse(text = as.character(lab)) : <text>:1:22: inesperado '<'
1: P(16.791<=chi[70]^{2}<
^
为什么解析第一个“ <=”但不解析第二个“ <”
问题在于绘制表达式的?plotmath
方法要求您具有有效的R表达式。 和类似的东西
1 < 2 < 3
会在R中产生语法错误。您不能有一系列这样的不等式。最简单的方法是通过list()
调用在表达式中进行某种分组。 例如
ggplot(data = data.frame(x = c(0, 70)), aes(x)) +
stat_function(fun = dchisq, args = list(df = 30))+
annotate("text", x = c(7), y = c(0.019),
label = "P(list(16.791<=chi[70]^{2})<46.979)==0.95",parse = TRUE , size=4 , fontface="bold")
这也应该起作用:
ggplot(data.frame(x = c(0, 70)), aes(x = x)) +
stat_function(fun = dchisq, args = list(df = 30))+
annotate("text", x = 7, y = 0.019,
label = "paste(italic(P), \"(16.791 <=\",italic(chi)[70]^2,\"<46.979)==0.95\")",parse = TRUE , size=4 , fontface="bold")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.