问题
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