Today encountered an exception, the code is as follows:
set.seed(12345)require(ggplot2)AData <- data.frame(Glabel=LETTERS[1:7], A=rnorm(7, mean = 0, sd = 1), B=rnorm(7, mean = 0, sd = 1))
i <- 2j <- 3p <- ggplot(data=AData, aes(AData[, i], AData[, j])) + geom_point() + theme_bw()
p # all rightp <- p + geom_text(aes(data=AData, label=Glabel), size=3, vjust=1.25, colour="black")
p # Error: Aesthetics must either be length one, or the same length as the dataProblems:AData
下面的代码就ok:
example <- data.frame(r=c(5,4,3),theta=c(0.9,1.1,0.6))
myplot <- ggplot(example, aes(r, theta)) + geom_point(size=3.5) +
geom_text(aes(label=rownames(example)), size=4.4, hjust=0.5, vjust=-1)
根据异常信息,应该是说Glabel与AData的长度不同,但具体什么原因不了解。
stackover上面的解释是:对于0.9.0版本的ggplot2有这个问题,0.9.1版本中已经解决。(http://stackoverflow.com/questions/10628847/geom-boxplot-with-precomputed-values)
利用installed.packages()命令,看到我的ggplot2的版本是1.0.1,应该没有问题,奇怪。
stackoverflow上另外一个类似的帖子是:http://stackoverflow.com/questions/20057452/aesthetics-must-either-be-length-one-or-the-same-length-as-the-dataproblems
但是与我遇到的问题不大一样,暂无解.
Exception: Error:aesthetics must either be length one, or the same length as the Dataproblems:adata