Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://stats.stackexchange.com/questions/3842/how-to-create-a-barplot-diagram-where-bars-are-side-by-side-in-r
- accepted
- I shall assume that you are able to import your data in R with read.table() or the short-hand read.csv() functions. Then you can apply any summary functions you want, for instance table or mean, as below:
- x <- replicate(4, rnorm(100))
- apply(x, 2, mean)
- or
- x <- replicate(2, sample(letters[1:2], 100, rep=T))
- apply(x, 2, table)
- The idea is to end up with a matrix or table for the summary values you want to display.
- For the graphical output, look at the barplot() function with the option beside=TRUE, e.g.
- barplot(matrix(c(5,3,8,9),nr=2), beside=T,
- col=c("aquamarine3","coral"),
- names.arg=LETTERS[1:2])
- legend("topleft", c("A","B"), pch=15,
- col=c("aquamarine3","coral"),
- bty="n")
- The space argument can be used to add an extra space between juxtaposed bars.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement