given the code
set.seed(1234)
dat <- data.frame(cond = factor(rep(c("A","B"), each=200)),
rating = c(rnorm(200),rnorm(200, mean=.8)))
head(dat)
ggplot(dat, aes(x=rating)) + geom_freqpoly()
I need to change the y-axis to percentage of the maximum count. What is the best approach?
Further edited: I am not looking for a way to show the percentage of the total data points, but to set the maximum count as 100%, and show all the other bins as a percentage of that max. So the y axis would run from 1-100, with the top of the peak at 100.
I was a bit confused as to what you were asking initially, but now I understand: you want to represent the y-axis "normalized" to ..count..
, where your highest point is equal to 1.0 (maximum value), and all other points are equal value / maximum value
.
For that, this should work:
ggplot(dat, aes(x=rating, y=..count../max(count))) + geom_freqpoly()
If you want to change the values to be from 0 to 100 (instead of 0 to 1), then just multiply by 100:
ggplot(dat, aes(x=rating, y=(..count../max(count))*100)) + geom_freqpoly()