Reputation: 11
I'm trying to create a bar graph with percents on the y-axis. This is my current code but it outputs a graph with proportions on the y-axis. How could I change that?
ggplot(data = Access.Use,aes(fill=Access)) +
geom_bar(aes(x=Access, y = (..count..)/sum(..count..)), fill="lightblue") +
ylab("Proportion of Participants") + ylim(0,1) +
xlab("Availability and Use") + theme_bw() +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
Upvotes: 0
Views: 33
Reputation: 24069
You can scale_y_continuous(labels = scales::percent)
from the scales package.
Access.Use <- data.frame(Access=c("A", "B", "C", "A"))
ggplot(data = Access.Use) +
geom_bar(aes(x=Access, y = (..count..)/sum(..count..)), fill="lightblue") +
ylab("Proportion of Participants") +
xlab("Availability and Use") +
scale_y_continuous(labels = scales::percent) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
Upvotes: 1