简体   繁体   English

美学长度必须为1或与数据相同

[英]Aesthetics must be either length 1 or the same as the data

I want to add a few points to my ggplot, however when I add a few extra points it gives bugs and says 'Aesthetics must be either length 1 or the same as the data', what's wrong here and how to fix? 我想在ggplot中添加一些点,但是当我添加一些额外的点时,它会带来错误并说“美学必须为1或与数据相同”,这是怎么回事,以及如何解决?

    ggplot(as.data.frame(AAPLtrans), mapping = aes(x = AAPLtrans$Date, y = AAPLtrans$Adj.Close, group=1)) + 
      geom_point(size=I(0.2)) + aes(colour = factor(DBOTfunc(num))) +
      geom_line() + 
      geom_point(aes(x=AAPL[P[num,][5],]$Date, y=AAPL[P[num,][5],]$Adj.Close), colour="black", shape=1, size=3) + 
      geom_point(aes(x=AAPL[P[num,][4],]$Date, y=AAPL[P[num,][4],]$Adj.Close), colour="black", shape=1, size=3) + 
      geom_point(aes(x=AAPL[P[num,][3],]$Date, y=AAPL[P[num,][3],]$Adj.Close), colour="black", shape=1, size=3) + 
      geom_point(aes(x=AAPL[P[num,][2],]$Date, y=AAPL[P[num,][2],]$Adj.Close), colour="black", shape=1, size=3)

One possibility is that you have inadvertently misspelled one of the names of your variables in the aes mapping . 一种可能是您在aes映射中无意中拼写了变量名之一。 Possibly an upper/lower case difference? 可能是大小写不同吗? This will create a length mismatch, with the difference being the # of columns misspelled. 这将造成长度不匹配,不同之处是列号拼写错误。

您有一个没有aes包装器的geom_line(),可以吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM