Reputation: 21
I'm trying to combine a bar plot and line plot in ggplot using continuous and categorical variables. I basically need to do something like this:
So far I've got this code:
ggplot(data=nutrients, aes(x=Plot, y=Level, fill=Factor)) +
geom_bar(stat="identity", position = 'dodge', colour="black")
Upvotes: 2
Views: 849
Reputation: 32548
ggplot(mtcars, aes(x = factor(cyl), y = wt, fill = factor(gear))) +
geom_bar(stat = "identity", position = "dodge") +
geom_line(aes(y = ave(wt, cyl, FUN = max), group = gear)) +
geom_point(aes(y = ave(wt, cyl, FUN = max), group = gear))
Change the FUN
as necessary
Upvotes: 1