具有明显差异和交互作用的小节? [英] Barplot with significant differences and interactions?

查看:109
本文介绍了具有明显差异和交互作用的小节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想可视化我的数据和方差分析统计数据.通常使用带有添加的线的条形图来执行此操作,这些线表示明显的差异和相互作用.如何使用R绘制这样的情节?

I would like to visualize my data and ANOVA statistics. It is common to do this using a barplot with added lines indicating significant differences and interactions. How do you make plot like this using R?

这就是我想要的:

我目前正在使用barplot2{ggplots}来绘制条形图和置信区间,但是我愿意使用任何程序包/过程来完成工作.为了获取统计信息,我目前使用TukeyHSD{stats}pairwise.t.test{stats}进行差异,并使用anova函数之一(aovezANOVA{ez}gls{nlme})进行交互.

I am currently using barplot2{ggplots} to plot bars and confidence intervals, but I am willing to use any package/procedure to get the job done. To get the statistics I am currently using TukeyHSD{stats} or pairwise.t.test{stats} for differences and one of the anova functions (aov, ezANOVA{ez}, gls{nlme}) for interactions.

请给您一个想法,这是我目前的情节:

Just to give you an idea, this is my current plot:

推荐答案

当您使用库gplots中的函数barplot2()时,将给出使用此方法的示例.

As you are using function barplot2() from library gplots, will give example using this approach.

首先,按照barplot2()函数的帮助文件中的说明制作barplot. ci.lci.u是伪造的置信区间值.条形图应另存为对象.

First, made barplot as given in help file of barplot2() function. ci.l and ci.u are fake confidence interval values. Barplot should be saved as object.

hh <- t(VADeaths)[1:2, 5:1]
mybarcol <- "gray20"
ci.l <- hh * 0.85
ci.u <- hh * 1.15
mp <- barplot2(hh, beside = TRUE,
               col = c("grey12", "grey82"),
               legend = colnames(VADeaths)[1:2], ylim = c(0, 100),
               cex.names = 1.5, plot.ci = TRUE, ci.l = ci.l, ci.u = ci.u)

如果您查看对象mp,它包含所有条形的x坐标.

If you look on object mp, it contains x coordinates for all bars.

 mp
     [,1] [,2] [,3] [,4] [,5]
[1,]  1.5  4.5  7.5 10.5 13.5
[2,]  2.5  5.5  8.5 11.5 14.5

现在,我使用较高的置信区间值来计算段的y值的坐标.分段将从比置信区间结束高1的位置开始. y.cord包含四行-第一和第二行对应于第一栏,其他两行对应于第二栏.最高y值是根据每个条形对的置信区间的最大值计算得出的. x.cord值只是重复mp对象中的相同值,每2次.

Now I use upper confidence interval values to calculate coordinates for y values of segments. Segments will start at position that is 1 higher then the end of confidence intervals. y.cord contains four rows - first and second row correspond to first bar and other two rows to second bar. Highest y value is calculated from the maximal values of confidence intervals for each bar pair. x.cord values just repeat the same values which are in mp object, each 2 times.

y.cord<-rbind(c(ci.u[1,]+1),c(apply(ci.u,2,max)+5),
          c(apply(ci.u,2,max)+5),c(ci.u[2,]+1))
x.cord<-apply(mp,2,function(x) rep(x,each=2))

绘制小节后,使用sapply()使用计算出的坐标绘制五个线段(由于这次有5组).

After barplot is made use sapply() to make five line segments (because this time there are 5 groups) using calculated coordinates.

sapply(1:5,function(x) lines(x.cord[,x],y.cord[,x]))

要在段上方绘制文本,请计算x和y坐标,其中x是两个条形x值的中间点,y值是根据每个条形对的置信区间的最大值加上一些常数来计算的.然后使用功能text()添加信息.

To plot texts above the segments calculate x and y coordinates, where x is middle point of two bar x values and y value is calculated from the maximal values of confidence intervals for each bar pair plus some constant. Then use function text() to add information.

x.text<-colMeans(mp)
y.text<-apply(ci.u,2,max)+7
text(c("*","**","***","NS","***"),x=x.text,y=y.text)

这篇关于具有明显差异和交互作用的小节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆