我正在尝试制作显示数据的三个特征(SiteID、Group 和 TreatmentID)的箱线图。我能够成功表示两个变量(SiteID 和 Group),如下面的代码所示,但是当我尝试更改箱线图中点的颜色以表示我的第三个特征(TreatmentID)时,它会覆盖原始分组. 有人知道我该如何解决这个问题吗?
这是我的代码:
myData <- structure(list(SiteID = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 3L, 3L), .Label = c("1", "2", "3"), class = "factor"), Group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Shale Hills", "Sleepers River"), class = "factor"), TreatmentID = c("A", "R", "A", "R", "A", "R", "A", "R", "A", "R", "A", "R"), DOCmgkg = c(3.63, 6.43, 7.48, 10.04, 7.3, 8.2, 3.1, 8.1 ,6.36 , 1.8, 4.5, 5.4)), row.names = c("4", "8", "16", "20", "24", "28", "32", "36", "40", "44", "48", "52"), class = "data.frame")
# Bring in plot basics
library(ggplot2)
p<-ggplot(myData, aes(x=SiteID, y=DOCmgkg, fill=Group)) +
geom_boxplot(position=position_dodge(1))
# Successful attempt at displaying two characteritics
p + geom_point(position=position_dodge(1), pch=21)
# Unsuccessful attempt at displaying three characteritics
p + geom_point(position=position_dodge(1), pch=21, aes(fill=factor(TreatmentID)))
最好的,托马斯
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句