RStudio: How to convert the horizontal axis to a natural log-scale in ggplot2?

1.2k views Asked by At

I am using the package tidyverse and would like to scale the X axis of the below plot to the natural log of the values.

require(tidyverse)
require(gapminder)
gapminder07 <- dplyr::filter(gapminder, year == 2007)
ggplot(data = gapminder07) + 
geom_text(mapping = aes(x = gdpPercap, y = lifeExp, label = country))

It must be scaled to natural log.

1

There are 1 answers

0
neilfws On BEST ANSWER
+ scale_x_continuous(trans = scales::log_trans(),
                     breaks = scales::log_breaks())

should do it.