Skip to content

Instantly share code, notes, and snippets.

@lukmdo
Last active December 29, 2015 07:19
Show Gist options
  • Save lukmdo/7634956 to your computer and use it in GitHub Desktop.
Save lukmdo/7634956 to your computer and use it in GitHub Desktop.
R multibar plot
library(Hmisc) # summarize
dx = summarize(mtcars$hp, llist(mtcars$cyl, mtcars$gear), sum)
dx = summarize(mtcars$hp, llist(mtcars$cyl, mtcars$gear), mean)
names(dx) = c("cyl", "gear", "hp")
dx.t = xtabs(hp ~ cyl + gear, dx)
barplot(dx.t,
beside=T,
col=rainbow(3),
xlab="gear", ylab="Mean(hp)",
legend = rownames(dx.t)
args.legend = list(x="topleft", title="Num cyl"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment