davidcarslaw / openair

Tools for air quality data analysis
https://davidcarslaw.github.io/openair/
GNU General Public License v2.0
304 stars 113 forks source link

scatterPlot: Adjusting axis tick interval #98

Closed josephko91 closed 2 months ago

josephko91 commented 7 years ago

Dear @davidcarslaw I am new with openair, and fairly new with R. I cannot for the life of me figure out how to manually adjust the x-axis tick marks. For sake of example, I have x = date and y = CBL. I want the x-axis tick to be spaced out for every single day, instead of the default - which is currently showing as every 7 days. I've tried passing the scatterPlot to a variable, then calling the plot, and then using axis() to try to manipulate the plot; but I end up getting an error "plot,new has not been called yet".

Can you please help or direct me to the right resources? It's hard to get help since this function is under this specific package. Thanks!

MohoWu commented 7 years ago

openair plots graphs using lattice package. Try searching questions with "lattice" at the end. Here's a discussion that may solve your problems: http://stackoverflow.com/questions/17584248/exact-axis-ticks-and-labels-in-r-lattice-xyplot

jack-davison commented 2 months ago

I'm going to close this stale issue (8 years).

If this issue still persists, please feel free to re-open this issue.

If producing a scatter plot, you could look to use {ggplot2}, which allows for fine control over plot features:

library(openair)
library(ggplot2)

plt <-
  ggplot(mydata, aes(x = nox, y = o3)) +
  geom_point() +
  labs(x = openair::quickText("NOx (ug/m3)"),
       y = openair::quickText("O3 (ug/m3)")) +
  theme_bw(base_size = 14)

# every 100
plt + scale_x_continuous(breaks = seq(0, 1200, 100))
#> Warning: Removed 4114 rows containing missing values or values outside the scale range
#> (`geom_point()`).


# every 300
plt + scale_x_continuous(breaks = seq(0, 1200, 300))
#> Warning: Removed 4114 rows containing missing values or values outside the scale range
#> (`geom_point()`).


# let {scales} pick roughly 6 nice breaks
plt + scale_x_continuous(breaks = scales::pretty_breaks(n = 6))
#> Warning: Removed 4114 rows containing missing values or values outside the scale range
#> (`geom_point()`).

Created on 2024-09-02 with reprex v2.1.1

Cheers, Jack