Reputation: 1031
The following snippet creates stacked bars showing the distribution of "clarity" by "cut".
data(diamonds)
qplot(cut, data=diamonds, geom="bar", fill=clarity, position="fill")
Another plot shows the total distribution of "clarity" for the entire dataset.
qplot(x=factor(""), data=diamonds, geom="bar", fill=clarity, position="fill")
Is there a way to add the second plot as an extra bar to the first plot, say with label "total"?
Upvotes: 1
Views: 179
Reputation: 110024
Many approaches but here's one:
diamonds2 <- diamonds
diamonds2$cut <- "Total"
diamonds3 <- rbind(diamonds, diamonds2)
qplot(cut, data=diamonds3, geom="bar", fill=clarity, position="fill")
Upvotes: 3