0

I would like to make a density plot with a user-defined x-axis:

library(ggplot2)

ggplot(dataset, aes(x = VarX, fill = varFill)) +
scale_x_continuous(breaks = seq(0, 1000, by = 100)) +
geom_density(alpha= .5, aes(coulour = varFill)) +
xlim(c(0, 1000))

However, when I try the code above, I get the following message:

"Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale."

The the "standard"-axis is shown.

I don't know, why the x-scale should be set already? Can anyone help please?

Cettt
  • 11,460
  • 7
  • 35
  • 58
D. Studer
  • 1,711
  • 1
  • 16
  • 35
  • Why are you trying to use both `scale_x_continuous` and `xlim`? When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input so we can run the code too to test possible solutions. – MrFlick Aug 02 '18 at 20:48
  • 4
    If you want to set both the `breaks` and the `limits`, skip `xlim` and use the `limits` argument in `scale_x_continuous()`: `limits = c(0, 1000)`. – aosmith Aug 02 '18 at 20:49

0 Answers0