I am trying to plot proportions on the y-axis of my bar graph, as opposed to the usual count.
I am doing something like the following:
ggplot(data=mpg, aes(model))+geom_bar(aes(y=stat(count/sum(count)))
I am getting a blank plot.
I am trying to plot proportions on the y-axis of my bar graph, as opposed to the usual count.
I am doing something like the following:
ggplot(data=mpg, aes(model))+geom_bar(aes(y=stat(count/sum(count)))
I am getting a blank plot.
are you talking about coord_flip()? This will turn your chart 90 degrees
EDITED, Added below:
Try this below
ggplot(data=mpg)+
geom_bar(mapping=aes(x=model, y=..prop.., group=1))
You need to create a data frame containing the proportions first, then use stat = "identity"
.
library(tidyverse)
mtcars %>%
as_tibble %>%
group_by(cyl) %>%
summarize(prop = n()/nrow(.)) %>%
ggplot() +
geom_bar(aes(cyl, prop), stat = "identity")