user20188476
user20188476

Reputation: 11

How to make proportions into percent for gglplot2

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

Answers (1)

Dave2e
Dave2e

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

Related Questions