0

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.

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • `ggplot(data = gapminder07) + geom_text(mapping = aes(x = gdpPercap, y = lifeExp, label = country)) + scale_x_log10()` ? – Ronak Shah Sep 29 '20 at 02:47
  • or `+coord_trans(x="log")`. I did a google search for the subject of this question and think the top 3 (for me) were perfectly relevant. And then I search SO for [`[r] ggplot2 log scale`](https://stackoverflow.com/search?q=%5Br%5D+ggplot2%20log%20scale) and found many similar questions with answers. – r2evans Sep 29 '20 at 02:48

1 Answers1

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

should do it.

neilfws
  • 32,751
  • 5
  • 50
  • 63