Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

r - Plotting point estimates with error bars for different groups

I have a set of f4 ratio statistics with standard errors for different populations/regional groups.

I want to make a plot where the X axis is the different groups and on the X axis I have the point estimates with error bars for 95% CIs. Basically, I want to graphically display how the values for my populations of interest fall out relative to each other and other groups.

My data basically looks like this:

Group   alpha   SE  Z   Sample size
Pop1    0.029000    0.003589    8.116   9
Pop2    0.031868    0.003498    8.231   9
Pop3    0.028969    0.003765    7.942   8
Pop4    0.030651    0.003479    8.792   10

alpha would be the point estimate and SE would be the standard error. (Z and sample size are irrelevant here).

Can anyone suggest a good way of doing this? Thanks!

(What I am looking for is something like Figure 2b here http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3493647/figure/f2/ except with error bars.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Is this helpful in any way?

# > dput(df)
df <- structure(list(Group = structure(1:4, .Label = c("Pop1", "Pop2", 
"Pop3", "Pop4"), class = "factor"), alpha = c(0.029, 0.031868, 
0.028969, 0.030651), SE = c(0.003589, 0.003498, 0.003765, 0.003479
), Z = c(8.116, 8.231, 7.942, 8.792), Sample.size = c(9L, 9L, 
8L, 10L)), .Names = c("Group", "alpha", "SE", "Z", "Sample.size"
), class = "data.frame", row.names = c(NA, -4L))
# > df
#   Group    alpha       SE     Z Sample.size
# 1  Pop1 0.029000 0.003589 8.116           9
# 2  Pop2 0.031868 0.003498 8.231           9
# 3  Pop3 0.028969 0.003765 7.942           8
# 4  Pop4 0.030651 0.003479 8.792          10

# install.packages("ggplot2", dependencies = TRUE)
require(ggplot2)

ggplot(df, aes(y = Group, x = alpha, xmin = alpha - SE,  
               xmax = alpha + SE, label = Group, 
               colour = as.factor(Sample.size))) + 
      geom_point(colour = "black") + geom_text(hjust = 1.2) + theme_classic() +
      theme(axis.title = element_blank(), axis.ticks = element_blank(), 
      axis.text.y = element_blank(), legend.position = "none") # +
      geom_errorbarh(height = .1)

sigh


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...