Skip to content

Instantly share code, notes, and snippets.

@stevenworthington
Created March 29, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenworthington/2243047 to your computer and use it in GitHub Desktop.
Save stevenworthington/2243047 to your computer and use it in GitHub Desktop.
barplot_values_ggplot2
library(ggplot2)
library(plyr)
data(mpg)
# create a data frame with averages and standard deviations
hwy.means <- ddply(mpg, c("class", "year"), summarize, hwy.avg = mean(hwy), hwy.sd = sd(hwy))
# barplot with values over bars
ggplot(hwy.means) +
geom_bar(aes(class, hwy.avg, fill = factor(year)), position = "dodge", colour = "black", size = 0.3) +
geom_text(aes(class, hwy.avg, label = sprintf("%2.1f", hwy.avg)),
position = position_dodge(width = 1), size = 3.5, vjust = -0.3, colour = "grey10") +
scale_fill_hue(c=90, l=55) +
theme_bw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment