美学必须是长度1或与数据相同(1) [英] Aesthetics must be either length 1 or the same as the data (1)

查看:2338
本文介绍了美学必须是长度1或与数据相同(1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ggplot2中混合注释和表达式语句。我得到一致的错误美学必须是长度1或与数据(1)相同。我首先想到的是,我在aes中的变量数量错了。这可能仍然是事实,但我无法绕着它修理。所以我搜索并发现了似乎无法解决潜在问题的错误和解决方案。这是我的代码:

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))))


推荐答案

使用 bquote ,但它看起来像你可以通过使用 paste0 和设置<$ c来实现你想要做的事情$ c> parse = TRUE 在注释中

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)

这篇关于美学必须是长度1或与数据相同(1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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