R:选择合适的图,以创建具有3个亚组的线图,每个点的样本尺寸以及亚组之间的显着性差异
显示体重对年龄(体重〜年龄)的依赖性,对于3个亚组(因此每个组都有自己的线路)。我还希望该图表显示:
- 每个点的样本量,含义为每个年龄段的每个子组的个体数量。
- 每个年龄段的亚组之间的显着性差异。 (tukeyhsd结果)
更重要的是:我必须重复几个参数(例如长度〜年龄和宽度〜年龄),并且可能必须进行几次,所以,例如 Geom_text
。
>我真的很想避免手动插入解决 例如:
我尝试了此代码:
plot_morphologic <- ggplot(data = weight_table,
mapping = aes(x = as.numeric(age),
y = weight, color=POPULATION))+
geom_line(se=TRUE)
但是,这为3个人群创建了一行...
我也尝试了以下方式:
plot_morphologic <- ggline(data=weight_table, x = "age", y = "weight", add = "mean_sd",
color = "POPULATION")+
stat_compare_means(aes(group = POPULATION), method = "anova", label = "p.signif",
label.y = c(40),na.rm=F)+
stat_n_text(group="POPULATION")
但是无法将样本尺寸拆分为每个子组子组。
我的数据的一个示例:
weight_table1
# A tibble: 246 × 4
ID POPULATION age weight
<chr> <chr> <chr> <dbl>
1 Shere Khan A 0 13.4
2 Shere Khan A 1 14.2
3 Shere Khan A 2 17.4
4 Serafina B 0 5.19
5 Serafina B 1 15.3
6 Serafina B 2 NA
7 Kaa A 0 7.68
8 Kaa A 1 6.92
9 Kaa A 2 19.4
10 Shenzi C 0 6.96
tnx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下基本r函数来实现所有这些:
plot
带有参数xlim
和ylim
设置为您要绘制的最大范围(通常是使用1.1*range(YourData $ yourrow)
左右计算的最大范围)。行绘制另外两行
。code = 3
>”的有趣咆哮;-)text
一起添加文本。我不明白为什么最后一步是重复用例的问题,因为您可以使用
sprintf(“ n =%i”,nrow(yourdata))
创建标签文本。You can achieve all this with the following base R functions:
plot
with parametersxlim
andylim
set to the maximum range you want to plot (usually automatically computed with1.1*range(yourdata$yourrow)
or so).lines
.points
andarrows
, as explained in this answer. Note the amusing rant about the "particularly intuitive parametercode=3
" ;-)text
.I do not see why the last step is a problem for repeated use cases, because you can programatically create the label text with
sprintf("n=%i", nrow(yourdata))
.