0

I am a beginner with R and ggplot and have been facing an issue with defining my x and y axis on a linegraph.

I have the following dataset called UK:

enter image description here

I want to plot the beds ratio evolution with

  • x axis from 2010 to 2021 with breaks of 1
  • y axis from 0 to 3 with break of 0,5

I coded the following:

ggplot(data=UK, aes(x = Year, y = Beds_1000, group = 1)) +
   geom_line(color = as.factor("red")) + 
   geom_point() + 
   scale_x_discrete(limits=c(2010,2021)) +   
   scale_y_discrete(limits=c(0,3)

However, the axis of my graph disappear and I get the following message:

Continuous limits supplied to discrete scale. ℹ Did you mean limits = factor(...) or scale_*_continuous()?

I tried using limits=factor() and scale_*_continuous() but it made no difference on the final graph. The axis disapear or stay the same as without those functions.

  • 2
    Welcome to SO! If your plot does not show all years I would guess that it is a numeric in which case using `scale_x_continuous(breaks = 2010:2021)` should fix your issue. For more help we need a [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data shared via `dput()` to run your code. Please do not post an image of code/data/errors [for these reasons](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557). – stefan Mar 12 '23 at 17:27
  • 1
    It did indeed work, thank you so much for the help! And I will in the future not post images of my data :) – Adeline Kugler Mar 13 '23 at 09:30

0 Answers0