Skip to content

Instantly share code, notes, and snippets.

@jlehtoma
Created January 3, 2012 08:06
Show Gist options
  • Save jlehtoma/1554016 to your computer and use it in GitHub Desktop.
Save jlehtoma/1554016 to your computer and use it in GitHub Desktop.
ggplot2, levels and legend
library(ggplot2)
data <- data.frame('Puolue'=factor(c('A', 'B', 'C')),
'Kannatus'=c(4, 6, 8))
p <- ggplot(data, aes(fill=Puolue, y=Kannatus, x=rev(Puolue)))
p + geom_bar(stat="identity") +
scale_x_discrete(breaks=data$Puolue, labels=rev(data$Puolue)) + coord_flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment