1

Here's my data:

   year   means   stder
1 A_1996 4.1291 0.19625
2 B_1997 3.4490 0.18598
3 C_1998 4.1166 0.15977
4 D_1999 3.6500 0.15093
5 E_2000 3.9528 0.14950
6 F_2001 2.7318 0.13212

This is all the data I have. I'd like to plot these using the ggplot2 package, if possible. X axis will be year, and Y axis will be means. Each year will have one point -its corresponding mean value, with the respective standard error values as the "whiskers" around that point. How would I do this using the ggplot() function?

I think I'm mainly confused on how to put the standard error data into the ymin and ymax inputs.

I started looking here, but the beginning data is different, so I'm a little confused.

Plotting means and error bars (ggplot2)

1 Answer 1

3

Simple plot using general ggplot2 commands:

library(ggplot2)
df$year <- as.numeric(gsub(".*_", "", df$year))
ggplot(df, aes(year, mean)) +
    geom_point() +
    geom_errorbar(aes(ymin = mean - stder, 
                      ymax = mean + stder))

Same plot with fancier visuals:

ggplot(df, aes(year, mean)) +
    geom_point(size = 3) +
    geom_errorbar(aes(ymin = mean - stder, 
                      ymax = mean + stder),
                  width = 0.5, size = 0.5) +
    theme_bw() +
    labs(x = "Year",
         y = "Mean",
         title = "Change in mean over the period")

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.