Showing percentage instead of counts in a bar plot - ggplot2 - R

0 votes

I am working with the 'mtcars' dataset and have made this bar plot for the 'cyl' column:

image

For the y-axis, i want to see percentage instead of count. Is that possible?

May 28, 2018 in Data Analytics by BHARANI
• 410 points
1,545 views

1 answer to this question.

0 votes

Load the 'scales' package first, which gives different attributes to alter your scales.

library(scales)

Now, the below command is what you need:

ggplot(data = mtcars,aes(x=factor(cyl)))+geom_bar()+scale_y_continuous(labels=percent)

image

answered May 28, 2018 by Bharani
• 4,560 points

Related Questions In Data Analytics

0 votes
1 answer

Change the order of legend values in a plot in R

@prardhana, Use scale_fill/color/size_discrete/contin....(labels = c()). compare both to see ...READ MORE

answered Nov 4 in Data Analytics by payal
66 views
0 votes
1 answer
0 votes
1 answer

How to create dummy variables based on a categorical variable of lists in R?

You can use mtabulate in the following way: library(qdapTools) cbind(data[1], ...READ MORE

answered Apr 13, 2018 in Data Analytics by CodingByHeart77
• 3,690 points
622 views
+1 vote
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

answered Apr 13, 2018 in Data Analytics by darklord
• 6,190 points
219 views
0 votes
1 answer

How to plot side-by-side Plots with ggplot2 in R?

By Using gridExtra library we can easily ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,907 views
0 votes
1 answer

Aligning title in ggplot2

You can use the theme layer to ...READ MORE

answered Apr 27, 2018 in Data Analytics by Bharani
• 4,560 points
882 views
0 votes
1 answer

Making a ggplot2 plot without any legends,axes or axis labels

The below command will give you the ...READ MORE

answered May 29, 2018 in Data Analytics by Bharani
• 4,560 points
72 views
0 votes
1 answer
0 votes
1 answer

Changing the order of bars in a bar-plot - ggplot2 - R

You can use the scale_x_discrete() function with ...READ MORE

answered May 28, 2018 in Data Analytics by Bharani
• 4,560 points
3,853 views
0 votes
1 answer

Removing outliers from a box-plot - ggplot2 - R

You just have to add 'outlier.shape=NA' inside ...READ MORE

answered May 31, 2018 in Data Analytics by Bharani
• 4,560 points
4,493 views