Suppose I have the following data:
Fruit <- c(rep(\"Apple\",3),rep(\"Orange\",5))
Bug <- c(\"worm\",\"spider\",\"spider\",\"worm\",\"worm\",\"worm\",\"
Fruit <- c(rep("Apple",3),rep("Orange",5))
Bug <- c("worm","spider","spider","worm","worm","worm","worm","spider")
df <- data.frame(Fruit,Bug)
ggplot(df, aes(Fruit, ..count..)) + geom_bar(aes(fill = Bug), position = "dodge")
This is pretty easy to do with a two way table:
dat <- data.frame(table(df$Fruit,df$Bug))
names(dat) <- c("Fruit","Bug","Count")
ggplot(data=dat, aes(x=Fruit, y=Count, fill=Bug)) + geom_bar(stat="identity")