Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(lattice)
- library(dplyr)
- dat <- data.frame(fruit = rep(c("apple", "orange", "banana"), each=2),
- count = c(20, 40, 30, 70, 40, 50),
- site = rep(c("site_A", "site_B"), 3))
- barchart(count ~ fruit, groups = site, dat,
- auto.key = list(space = "right"))
- dat2 <- group_by(dat, fruit) %>% summarise(count = sum(count)) %>%
- mutate(ones = 1)
- barchart(count ~ ones, groups = fruit, dat2, stack = TRUE,
- auto.key = list(space = "right"), horizontal = FALSE)
- barchart( ~ count, groups = fruit, dat2, stack = TRUE,
- auto.key = list(space = "right"))
- library(latticeExtra)
- barchart(count ~ fruit, groups = site, dat,
- auto.key = list(space = "right"),
- par.settings = ggplot2like(n = nlevels(dat$site)),
- axis = axis.grid)
- barchart(count ~ ones, groups = fruit, dat2, stack = TRUE,
- auto.key = list(space = "right"),
- par.settings = ggplot2like(n = nlevels(dat$fruit)),
- axis = axis.grid, horizontal = FALSE)
- barchart( ~ count, groups = fruit, dat2, stack = TRUE,
- auto.key = list(space = "right"),
- par.settings = ggplot2like(n = nlevels(dat$fruit)),
- axis = axis.grid)
- library(ggplot2)
- ggplot(dat, aes(fruit, count, fill = site)) +
- geom_bar(stat="identity", position="dodge")
- ggplot(dat2, aes(ones, count, fill = fruit)) +
- geom_bar(stat="identity", position="stack")
Advertisement
Add Comment
Please, Sign In to add comment