0

Currently, I wish to produce a smooth curve in the ggplot2. To give a proper view of the data, I need to limit the domain of the x-axis and log the scale for the x-axis. My code is as follows:

sample <- ggplot(x, aes(abc, xyz)) +
          scale_x_log10() + 
          scale_x_continuous(1,10000) +
          #xlim(1, 10000)

          ### attempted xlim as opposed to scale_x_continuous with the same 
          ### result.

The warning I receive is as follows, "Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale."

Basically, I get to choose one or the other function.

Is there a mechanism to log the x-axis scale and also set the domain for be 1 to 10,000 without one one function overriding the other?

If you require more details, please feel free to comment. I have attempted to research a similar question to no avail, so if you find this to be a duplicate, do not hesitate to mark it as such.

M--
  • 25,431
  • 8
  • 61
  • 93
  • 4
    Possible duplicate of [ggplot scale\_y\_log10() issue](https://stackoverflow.com/questions/9502003/ggplot-scale-y-log10-issue) – M-- Jun 09 '17 at 23:56

1 Answers1

0


library(ggplot2)

x <- data.frame(abc = runif(1000, 1, 100000),
                xyz = runif(1000, 1, 10))
ggplot(x, aes(abc, xyz)) +
  geom_point()

ggplot(x, aes(abc, xyz)) +
  geom_point() +
  scale_x_log10(limits = c(1, 10000))
#> Warning: Removed 927 rows containing missing values (geom_point).

yeedle
  • 4,918
  • 1
  • 22
  • 22
  • the range is [1, 10000], all the values greater than that (there are 927 of them) are removed from the plot. – yeedle Jun 09 '17 at 23:58
  • Let me clarify: setting `limits` in the `scale_x_log10` function removes all the points that are outside the limits, causing this warning. You can safely ignore it. – yeedle Jun 09 '17 at 23:59