在 ggplot r 中绘制多行的 TOTAL 误差条
我想按主题绘制数据,但添加总平均值和se的误差条。我的意思是,不是每个科目都有误差线。我尝试过 geom_errorbar 和 stat_summary 但仍然未能获得理想的绘图(参见我画的图)。
这是我用来绘制该图的代码(误差线是手动添加的)。
ggplot(ASD, aes(x=period, y=meanF0, group=subject, color=group)) +
geom_line(aes(color=group, size=group)) +
scale_size_manual(values=c(.6, .6, .6, .6)) +
theme_light()+
xlab("Period")+
ylab("F0 (Hz)")+
ggtitle("Mean F0 Adjustment (ASD Group)") +
geom_point()+
scale_color_manual(values=c("red")) +
theme(plot.title = element_text(size=14.5, face="bold", hjust = 0.5, family = "serif"),
axis.title.y= element_text(size=12, face = "bold", family = "serif"),
axis.title.x= element_text(size=12, face = "bold", family = "serif"),
axis.text.x = element_text(size=11, face="bold", family = "serif"),
axis.text.y = element_text(size=11, face="bold", family = "serif"))+
theme(legend.position = "none")+
geom_hline(yintercept=112.8, linetype="dashed",
color = "dark grey", size=.7)
有人可以帮忙吗?非常感谢!!!
I would like to plot the data by subject but adding the errorbar of the total mean and se. I mean, not an error bar for each subject. I've tried geom_errorbar and stat_summary but still failed to get my ideal plot (see the figure I drew).
and here is the code I used to draw this figure (the errorbars are added by hand).
ggplot(ASD, aes(x=period, y=meanF0, group=subject, color=group)) +
geom_line(aes(color=group, size=group)) +
scale_size_manual(values=c(.6, .6, .6, .6)) +
theme_light()+
xlab("Period")+
ylab("F0 (Hz)")+
ggtitle("Mean F0 Adjustment (ASD Group)") +
geom_point()+
scale_color_manual(values=c("red")) +
theme(plot.title = element_text(size=14.5, face="bold", hjust = 0.5, family = "serif"),
axis.title.y= element_text(size=12, face = "bold", family = "serif"),
axis.title.x= element_text(size=12, face = "bold", family = "serif"),
axis.text.x = element_text(size=11, face="bold", family = "serif"),
axis.text.y = element_text(size=11, face="bold", family = "serif"))+
theme(legend.position = "none")+
geom_hline(yintercept=112.8, linetype="dashed",
color = "dark grey", size=.7)
Anyone could help? Thank you very much!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
annotate
添加误差线。我没有你的数据,所以我创建了自己的数据。您将需要每组的置信区间和平均值。我的按组平均值和按组置信区间存储在df4$meanV
和df4$ci
中。您可以将它们替换为您的变量名称。在注释中,您将在调用中包含数据框,就像在基本 R 图中一样。与基本 R 一样,您也可以只使用原始值。可以使用c()
连接多个值。如y = c(12, 10)
。如果您有任何疑问,请告诉我。Use
annotate
to add the error bars. I don't have your data, so I created my own. You're going to need the confidence interval and the average for each group. My average-by-group values and confidence interval-by-group are stored indf4$meanV
anddf4$ci
. You can replace these with your variable names. In annotate, you'll include the data frame in the call like you would in base R plots. Like base R, you can just use raw values, as well. Multiple values can be joined withc()
. As iny = c(12, 10)
. If you have any questions, just let me know.使用库
superb
,您可以获得一个计算均值和置信区间的函数。您可以使用各种布局来显示附加信息。其中一种布局显示单独的行,您还可以访问其他布局。一种称为
corset
-plot。它显示了单独的线条,但也显示了侧面的平滑密度。尝试获取:
请注意,我是superior的维护者。
Using the library
superb
, you get a function which computes the means and confidence intervals. You can, using various layouts, display additional information. One such layout displays the individvidual lines withYou also have access to other layouts. One is called
corset
-plot. It shows individual lines, but also a smooth density on the sides. TryYou get:
Note that I am the maintainer of superb.