2017-06-02 76 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(),可那是它嗎?

相關問題