r - 在 R Studio 中创建分组箱线图的问题
问题描述
我正在尝试使用 ggplot2 在 R Studio 中创建分组箱线图。
我的数据如下所示:
(总共 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")
我现在正在尝试创建一个分组箱线图,其中 APP.mm 在 x 轴上,重量在 Y 轴上,并且由 APP.mm 分组到发芽成功(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))
有人可以告诉我我在这里做错了什么吗?太感谢了!
解决方案
推荐阅读
- asp.net-mvc - 使用 Active Directory 组 MVC 进行 Windows 身份验证
- c# - 将生成的值从类发送到文本框
- python - 我将具有浮动值的列表的格式更改为 PYTHON 中的元组序列。但我得到的输出并不完全相同
- laravel - 具有 RAW 顺序的雄辩查询
- java - AppiumFieldDecorator 方法在最新的 serenity 版本中出现错误
- angular - Ionic App 性能差,速度慢
- asp.net-core - JwtBearer asp net core 从 api 获取签名密钥
- android - 如何更改 BottomSheetDialog 中的透明背景?
- database-design - 处理需要批准的记录更改的结构
- python-3.x - 无法连接 h2o 服务器 python3