我正在尝试使用ggplot2在R Studio中创建一个分组的Boxplot。
我的数据如下:
(总共4个不同的APP.mm值)
我的数据集的样本dput()
:
structure(list(APP.mm = c(408.5, 408.5, 408.5, 408.5, 408.5,
408.5, 408.5, 408.5, 408.5, 408.5, 408.5, 237.5, 237.5, 237.5,
237.5, 237.5, 237.5, 237.5, 237.5, 237.5, 237.5, 237.5, 237.5,
237.5, 237.5, 132.1, 132.1, 132.1, 132.1, 132.1, 132.1, 132.1,
274, 274, 274, 274, 274, 274, 274, 274, 274), Weight_mg = c(112,
106.72, 118.4, 62.3, 86.2, 70.3, 56.5, 71, 61.4, 61.7, 62.7,
81.1, 125.5, 71, 120.4, 75.3, 68.1, 95.9, 77.5, 95.5, 85.3, 64.1,
27.6, 20.5, 77.9, 86.3, 120, 100.2, 86.4, 67.8, 104.4, 90.1,
71.1, 89, 77.4, 77.1, 60.5, 78.7, 87.9, 71.1, 76.5), Germination = c(0L,
1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 1L,
1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L,
1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L)), .Names = c("APP.mm", "Weight_mg",
"Germination"), row.names = c(6L, 7L, 8L, 9L, 88L, 89L, 90L,
91L, 92L, 93L, 94L, 2111L, 2112L, 2113L, 2114L, 2115L, 2116L,
2117L, 2118L, 2119L, 2120L, 2121L, 2122L, 2123L, 2124L, 2674L,
2675L, 2676L, 2677L, 2678L, 2679L, 2680L, 3193L, 3194L, 3195L,
3196L, 3197L, 3198L, 3199L, 3200L, 3201L), class = "data.frame")
我现在正在尝试使用x轴上的APP.mm,Y轴上的权重和按APP.mm分组的值创建一个分组的Boxplot到萌芽成功(1)或没有萌发成功(0) )
我为R:
尝试了这些代码ggplot(data = gallsdtg, aes(x=APP.mm, y=Weight_mg)) +
geom_boxplot(aes(fill=Germination))
Warning message:
Continuous x aesthetic -- did you forget aes(group=...)?
ggplot(data = gallsdtg, aes(x=APP.mm, y=Weight_mg)) +
geom_boxplot(aes(group=Germination))
qplot(gallsdtg$APP.mm, gallsdtg$Weight_mg,
fill=factor(galls$Germination), geom="boxplot")
导致这个情节:
我在同一个数据结构上尝试了完全相同的代码,只是来自不同的位置并得到了我想要的情节。
qplot(germination2017extras$APP.mm, germination2017extras$Weight_mg,
fill=factor(germination2017extras$Germination), geom="boxplot",
xlab="mean APP in mm", ylab="Weight in mg", ylim=c(0,200))
有人能告诉我这里做错了什么吗?非常感谢你!