rggplot2scalenatural-logarithm

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


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.


Solution

  • + scale_x_continuous(trans = scales::log_trans(),
                         breaks = scales::log_breaks())
    

    should do it.