0

I am new to R so please forgive my ignorance (1 week in). I am trying to produce a scatterplot with a break at the y-axis so that it starts at 0 but then breaks before beginning at 20 (there are no data points between 0 and 20) I have tried a variety of commands using plotrix (by going through previous answered questions) but it doesn't change the outputting plot. The following code produces a nice plot formatted in the way I would like but I am not sure where or what to do next to then produce the break in the y-axis (perhaps denoted with //).

Age_perception <- ggplot(mydata
                       , aes(x=Age_years, y=Perception)) + 
  coord_cartesian(ylim = c(0, 100))+
  geom_point()+ 
  labs(x='Age in years', y='Perception') + 
  geom_smooth(method=lm, se=FALSE, fullrange=TRUE, col = 'black') + 
  apatheme +  
  theme(text = element_text(size=20)) 
Age_perception
  • please read https://stackoverflow.com/questions/7194688/using-ggplot2-can-i-insert-a-break-in-the-axis It is not a good idea to split the axis. – Roman Aug 02 '17 at 13:43
  • https://stackoverflow.com/questions/44694496/y-break-with-scale-change-in-r/44697832#44697832 might suggest a useful approach - but why do you want to have the ylim go down to zero if there's no data there? – Miff Aug 02 '17 at 13:43
  • I do not think `ggplot2` supports breaks in axis. You might try faceting the plots to get a similar result. – Jindra Lacko Aug 02 '17 at 13:46
  • Thankyou for the immediate responses! Very grateful. I understand that I shouldn't split the axis, but I suppose- and related to Miff's question, is it really splitting if there is no data between 0 and 20? I'm not creating the illusion of anything being continuous when it is not for example. The reason I want the ylim to go to 0 is because I believe that its a requirement of the journal to start at 0 (and the supervisors!) – walrusandpossum Aug 02 '17 at 13:48
  • Thanks Jindra, no I believe you are right- I can't do this in ggplot, but is it possible, to use plotrix at the same time as ggplot? I am not sure what faceting is at this stage... – walrusandpossum Aug 02 '17 at 13:52
  • Something from [here](https://stackoverflow.com/questions/39733972/ggplot2-custom-grob-over-axis-lines/40622343#40622343) might help. – Sandy Muspratt Aug 02 '17 at 22:48

0 Answers0