【发布时间】:2017-11-04 04:55:32
【问题描述】:
我想在我的 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)
【问题讨论】:
-
我很困惑。这些点来自不同的数据集还是相同的数据集?
-
也许这和你想做的类似:stackoverflow.com/questions/31069324/…
-
好吧,我猜错误信息告诉你:aes 中的映射值必须是长度为 1 的向量或 as.data.frame(AAPLtrans) 的行数。情况似乎并非如此。也许你在某处构建子集并继承
ggplot中的全局 aes 映射。很难说 - 您可能希望提供 R 标签要求的最小可重现示例(将鼠标悬停在其上)。 -
此外,aes 子句中不应有任何 $s。