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
• 400 points
1,146 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,550 points

Related Questions In Data Analytics

0 votes
0 answers

Change the order of legend values in a plot in R

how to change the order of legend ...READ MORE

Jul 23 in Data Analytics by prardhana
20 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,680 points
453 views
0 votes
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,140 points
120 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,700 points
1,290 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,550 points
662 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,550 points
41 views
0 votes
0 answers
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,550 points
2,284 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,550 points
2,419 views