Brigadeiro
Brigadeiro

Reputation: 2945

Error when using `coord_trans(y = "log10")` in ggplot2

I am trying to use coord_trans() to transform the coordinate of my figure to log10, but I get an esoteric error.

Code:

library(gapminder)
library(ggplot2)

ggplot(data = gapminder,
       mapping = aes(x = year,
                     y = gdpPercap * pop)) +
  geom_smooth(method = "lm") + 
  coord_trans(y = "log10")

Error:

Error in if (zero_range(range)) zero_width else diff(range) : 
missing value where TRUE/FALSE needed
In addition: Warning message:
In trans$transform(limits) : NaNs produced

Upvotes: 0

Views: 749

Answers (1)

Nicolás Velasquez
Nicolás Velasquez

Reputation: 5898

If you are looking for a solution to plot it, try

library(gapminder)
library(ggplot2)

ggplot(data = gapminder,
       mapping = aes(x = year,
                     y = log10(gdpPercap * pop))) +
  geom_smooth(method = "lm")

enter image description here

Upvotes: 1

Related Questions