Aesthetics must be either length 1 or the same as the data (1)

女生的网名这么多〃 提交于 2019-12-25 08:59:24

问题


I am trying to mix annotate and expression statements in ggplot2. I'm getting a consistent error "Aesthetics must be either length 1 or the same as the data (1)". My first thought was that I had the wrong number of variables in aes. That might still be true, but I couldn't wrap my head around fixing it. So I searched and found errors and solutions that didn't seem to address the underlying problem. Here's my code:

r2.val <- .09
pl <- qplot(c(0,30))
pl+annotate(geom="text",x=0,y=28,label=(bquote(Value~is~sigma~R^{2}==.
(r2.val))))

回答1:


I'm not familiar with bquote but it looks like you can achieve what you're trying to do by using paste0 and setting parse = TRUE in annotate:

pl + annotate(geom="text", x=10, y=1, 
              label = paste0("Value~is~sigma~R^2==", r2.val), parse = TRUE)




回答2:


pl <- qplot(c(0,30))
r2.val = 0.42
pl+annotate(geom="text",x=8,y=-.2,label=(paste("Value~is~sigma~R^{2}==",
                                               (r2.val))))

?



来源:https://stackoverflow.com/questions/43551846/aesthetics-must-be-either-length-1-or-the-same-as-the-data-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!