Skip to content

Instantly share code, notes, and snippets.

@djhocking
Created March 12, 2014 20:47
Show Gist options
  • Save djhocking/9515935 to your computer and use it in GitHub Desktop.
Save djhocking/9515935 to your computer and use it in GitHub Desktop.
Error bars using ggplot
### ggplot ###
# Refs: http://learnr.wordpress.com/2010/02/25/ggplot2-plotting-dates-hours-and-minutes/
# http://had.co.nz/ggplot2/
# http://wiki.stdout.org/rcookbook/Graphs/Plotting%20means%20and%20error%20bars%20%28ggplot2%29
library(ggplot2)
ggplot(data = gCount, aes(x = date, y = count, group = trt)) +
#geom_point(aes(shape = factor(trt))) +
geom_point(aes(colour = factor(trt), shape = factor(trt)), size = 3) +
geom_errorbar(aes(ymin=count-se, ymax=count+se), width=.1) +
# scale_shape_manual(values=c(24,21)) + # explicitly have sham=fillable triangle, ACCX=fillable circle
#scale_fill_manual(values=c(“white”,”black”)) + # explicitly have sham=white, ACCX=black
xlab(“Date”) +
ylab(“Mean number of salamander captures per night”) +
scale_colour_hue(name=”Treatment”, # Legend label, use darker colors
l=40) + # Use darker colors, lightness=40
theme_bw() + # make the theme black-and-white rather than grey (do this before font changes, or it overrides them)
opts(legend.position=c(.2, .9), # Position legend inside This must go after theme_bw
panel.grid.major = theme_blank(), # switch off major gridlines
panel.grid.minor = theme_blank(), # switch off minor gridlines
legend.title = theme_blank(), # switch off the legend title
legend.key = theme_blank()) # switch off the rectangle around symbols in the legend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment