2017-06-02 83 views
0

我想向我的ggplot添加几个点,但是当我添加一些额外的点时,它会给出错误并说'美学必须是长度1或相同数据',这里有什么问题以及如何解决?美学必须是长度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) 
+0

我很困惑。点数来自不同的数据集还是相同的数据集? –

+0

也许这与你想要做的相似:https://stackoverflow.com/questions/31069324/adding-points-from-other-dataset-to-ggplot2 –

+0

嗯,我想错误信息告诉你: aes内的映射值必须是长度为1的矢量或as.data.frame(AAPLtrans)的行数。这似乎并非如此。也许你在sgwhere里建立子集并继承'ggplot'内的全局aes映射。很难说 - 你可能想要提供一个最小的可重复例子,如R标签所示(悬停在它上面)。 – lukeA

回答

0

你有没有aes包装的geom_line(),可那是它吗?

相关问题