how to change radial axis tick and frame extent in R openair polarplot

76 views Asked by At

I am using opeair polarplot function to generate a plot like this. polarPlot from https://davidcarslaw.github.io/openair/reference/polarPlot.html#details

However, I am unable to customize plot appearenace.

  • I want to change the radius of innner circles representing winds and want to put them at 3,6,9,12,18 m/s.
  • I do not want frame cropping outermost circle full as shown here. I want full circle.
  • I want change orientation of key.header (which is the colorbar label)

I have tried syntax applied to ggplot2 but it doesn't work with this function. I would be grateful for any lead on this.

my code:

polarPlot(data, pollutant="pol", 
          x="Wind_spd_m_s", 
          wd="Wind_Direction", 
          col="turbo", 
          limits =c(40,400), 
          key.position="right", 
          key.header = "pol conc", 
          key.footer="", 
          units = "ms-1",
          breaks = seq(0, 18, by = 3))
           
1

There are 1 answers

1
Allan Cameron On

As well as drawing the polar plot, the polarPlot function invisibly returns an object which contains a data frame of x, y, z values that allows you to draw the plot in whatever format you like.

I find ggplot the easiest system to use to customize plots, so you can replicate the graphical output of polarPlot with custom breaks and a rotated legend header as follows:

library(ggplot2)

df <- openair::polarPlot(openair::mydata, pollutant = "nox")$data

ggplot(df, aes(u, v, fill = z)) +
  geom_raster(na.rm = TRUE, interpolate = TRUE) +
  ggforce::geom_circle(data = data.frame(r = c(3, 6, 9, 12, 18)),
              aes(x0 = 0, y0 = 0, r = r), inherit.aes = FALSE,
              linetype = 2, color = 'gray75') +
  geom_hline(yintercept = 0) +
  geom_vline(xintercept = 0) +
  scale_fill_gradientn(name = 'mean', na.value = NA,
                       colours = rev(RColorBrewer::brewer.pal(11, "Spectral"))) +
  labs(x = NULL, y = NULL) +
  theme_classic(base_size = 16) +
  theme(panel.border = element_rect(fill = NA, linewidth = 1),
        panel.background = element_blank(),
        legend.background = element_blank(),
        axis.line = element_blank(),
        legend.title = element_text(angle = 90, vjust = 1)) +
  coord_equal(expand = FALSE) 

enter image description here