Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (5.3k points)

I have an object from ggplot2, say myPlot, how can I identify the ranges for the x and y axes?

It doesn't seem to be a simple multiple of the data values' range, because one can rescale plots, modify axes' ranges, and so on.  findFn (from sos) and Google don't seem to be turning up relevant results, other than how to set the axes' ranges.

1 Answer

0 votes

To extract the plot axes ranges for a ggplot2 object, you can use the following:

For the plot “p” given below:

p <- ggplot(data = mpg,aes(hwy, cty)) +


  facet_grid(. ~ manufacturer) + 

  coord_cartesian(xlim = c(20,40))+

  theme(strip.text.x = element_text(size = 10, colour = "black", angle = 90))

To extract x and y ranges:



[1] 20 40



Related questions

Browse Categories