-1

I have a set of statistics with standard errors for different 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.02    0.001   8.123   10
Pop2    0.03    0.002   8.456   10
Pop3    0.02    0.003   7.789   8
Pop4    0.03    0.004   8.123   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.)

  • It's more likely that we will be able to help you if you make a minimal reproducible example to go along with your question. Something we can work from and use to show you how it might be possible to solve your problem. You can have a look at [this SO post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to make a great reproducible example in R. Furthermore, it would also be helpful if you outline what you have already tried. – Eric Fail Jan 13 '16 at 22:33
  • You should post the code to do the data entry. If that is part of what you don't know how to accomplish then you should do some searching on how to do basic R activities first. This is not Code-Writing Central. Studying the "Introduction to R" as a first step appears necessary. As is learning how to search on R for answers to questions that have many answers. – IRTFM Jan 13 '16 at 22:44
  • It might be wise to start be some simple R tutorials, as @42- also points out. If you do not have the time for that you could take a look at [geom_text](http://docs.ggplot2.org/current/geom_text.html) and [geom_point](http://docs.ggplot2.org/current/geom_point.html) from the `ggplot2` package. To get that you need to run `install.packages("ggplot2", dependencies = TRUE)` and install it. To get help on any function in R you can type `??function` e.g. `??install.packages` – Eric Fail Jan 13 '16 at 22:47
  • Expanding on @EricFail, if you were using ggplot2, it'd be something like: `ggplot(data, aes(y = Group, x = alpha, xmin = alpha - SE, xmax = alpha + SE)) + geom_point() + geom_errorbarh()`. There are several more ways to plot just in ggplot2, as well as in base graphs and lattice. – oshun Jan 13 '16 at 23:54

1 Answers1

0

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

Eric Fail
  • 8,191
  • 8
  • 72
  • 128
  • 3
    This is why we tend to ask you to supply [a minimal reproducible example](http://stackoverflow.com/help/mcve) (yes, have a look at that page). More often than not people answer their own questions when they go through that exercise. Two pointers, you most likely want to rearrange your data from a `list` structure to a data-frame and second don't use `$` inside your `ggplot2` call. – Eric Fail Jan 14 '16 at 19:57