Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending % Symbol with y-axis values in ggplot2

Tags:

r

ggplot2

I want to appending % symbol with y-axis values in ggplot2. I used scale_y_continuous(labels=percent) but it first multiply the values with 100 and then attach % symbol whereas I need something like this 35% rather than 3,500%.

library(ggplo2)
library(scales)

p <- ggplot(mpg, aes(displ, cty)) + geom_point()

p + facet_grid(. ~ cyl)

p + facet_grid(. ~ cyl) + scale_y_continuous(labels=percent)

enter image description here enter image description here

like image 943
MYaseen208 Avatar asked Mar 13 '16 05:03

MYaseen208


1 Answers

Pasting the "%" onto the values seems to work fine

p + facet_grid(. ~ cyl) + scale_y_continuous(labels=function(x) paste0(x,"%"))
like image 185
Rorschach Avatar answered Sep 21 '22 00:09

Rorschach