Home > Software engineering >  change x limits with percent scale in ggplot histogram
change x limits with percent scale in ggplot histogram

Time:05-18

I am trying to plot histogram. I wish to set x-axis limit from 50% to 60%.

tbl <- tibble(x = runif(n = 100, min = 53, max = 58))

ggplot(tbl, 
       aes(x = x))   
  geom_histogram(bins = 50)   
  theme_bw()   
  scale_x_continuous(labels = scales::percent_format(scale = 1, 
                                                     limits = c(50, 60))) 

CodePudding user response:

Your limits are not in the right place:

scale_x_continuous(labels = scales::percent_format(scale = 1), 
                     limits = c(50, 60))
  • Related