0

So I am new to R and I am trying to use the ylim() function in order to zoom into the part of the graph that actually have data.

For example, when I say ylim(10,30) because my temperature points ranged from 10 to 30 degrees, it also uses the same 10,30 limit for salinity but that was not what I wanted since salinity has points from only 20 to 40 and chlorophyll level ranges from 0 to 10.

Therefore, I would like to use ylim(10,30) for temperature but ylim(20,40) for salinity and ylim(0,10) for chlorophyll but I am unsure how to do so. If this can be done through a geom_point() graph that would be ok as well. Because I'm new to R, could you tell me how to edit my current code to fix this or to add something to the code with the + symbol?

Thank you very much for the help.

ggplot(data = Factors, 
       mapping = aes(x = as.Date(Date,"%m/%d/%Y"), y =Variable, group = 1)) +
geom_line(group = 1) + 
facet_grid(rows=vars(Group)) + 
labs(x = "Date", y = "Variable") 
scale_x_date(date_breaks = "week", date_labels = "%b %d") + ylim(10,30). 

Graph without ylim applied: enter image description here

graph with ylim applied

data set

medium-dimensional
  • 1,974
  • 10
  • 19
R-ookie
  • 9
  • 1
  • Instead of sharing the plot with the entire RStudio screen, it's also possible to just share the plot: right click on the image, use "Save Image As" option and then directly add image to the post! :) – medium-dimensional Nov 23 '22 at 20:41
  • Does this answer your question? [ggplot2 change axis limits for each individual facet panel](https://stackoverflow.com/questions/51735481/ggplot2-change-axis-limits-for-each-individual-facet-panel) – Juan C Nov 23 '22 at 20:44
  • @R-ookie The code shared is missing a `+` sign between `labs(...)` and `scale_x_date(...)`. – medium-dimensional Nov 23 '22 at 20:45

0 Answers0