當使用標準的R圖形添加線性模型趨勢線的箱線圖使用:添加一個簡單的LM趨勢線到ggplot箱線圖
boxplot(iris[,2]~iris[,1],col="LightBlue",main="Quartile1 (Rare)")
modelQ1<-lm(iris[,2]~iris[,1])
abline(modelQ1,lwd=2)
然而,在GGPLOT2當使用這樣的:
a <- ggplot(iris,aes(factor(iris[,1]),iris[,2]))
a + geom_boxplot() +
geom_smooth(method = "lm", se=FALSE, color="black", formula=iris[,2]~iris[,1])
我得到以下錯誤:
geom_smooth: Only one unique x value each group.Maybe you want aes(group = 1)?
併線不會出現在我的陰謀。
在這兩種情況下使用的模型都是相同的。如果任何人都能指出我出錯的地方,那會很好。
編輯:以虹膜數據集爲例。
啊好吧,我不知道配方的內容。感謝您解決這個問題。 – JPD
請注意,我沒有「替換」公式。公式不是必需的,所以我刪除了它。 – Andrie
Pet peeve:「錯誤信息是自我解釋的」。如果這是自我解釋,OP就不會問這個問題了。 – Twitch