Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show two measurement units on axis ticks in ggplot2

How it is possible (if at all) to show two alternative units on axis ticks in ggplot2? What I would like to achieve is something like this:

enter image description here

like image 644
Boris Gorelik Avatar asked Mar 06 '13 12:03

Boris Gorelik


1 Answers

Here's a hacky way of doing that:

d = data.frame(x = 1:20, y = rnorm(20, 5, 5))

ggplot(data = d, aes(x = x, y = y)) +
  scale_x_continuous(breaks = c(1:20, seq(2.54, 20, 2.54)),
                     labels = c(1:20, paste0("\n", 1:as.integer(20/2.54), "\""))) +
  geom_point()

enter image description here

like image 168
eddi Avatar answered Sep 17 '22 23:09

eddi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!