Reputation: 95
I need to plot the geom_histogram but as the plots overlap, I want to plot it linear instead of bars, i.e, the x=hp, y=count (percent). Can anybody please help me find how to do it.
library(ggplot2)
library(scales)
ggplot(mtcars, aes(x=hp)) +
geom_histogram(binwidth=5)
I have done it by qplot but I need to do it in ggplot and the percent.
qplot(hp, data = mtcars, geom = "freqpoly", binwidth = 10)
Thanks
Upvotes: 0
Views: 658
Reputation: 30474
You can use geom_freqpoly
:
library(ggplot2)
library(scales)
ggplot(mtcars, aes(x=hp, y=..count../sum(..count..))) +
geom_freqpoly(binwidth=5) +
scale_y_continuous(labels = percent_format()) +
ylab("Percent")
Upvotes: 1