ropensci / rnoaa

R interface to many NOAA data APIs
https://docs.ropensci.org/rnoaa
Other
330 stars 84 forks source link

Include gaps in coverage plots #314

Closed philipshirk closed 4 years ago

philipshirk commented 5 years ago

I'm not sure if this really belongs in the issues or the forum, since it's more a feature request than a bug, but here it goes. In some cases stations are missing a lot of data, making the autoplot() of a meteo_coverage object very misleading. For example:

library(rnoaa)
library(ggplot2)

# Site
Safe_Harbor <-  'USC00367732'

# get data
dat <- meteo_pull_monitors(monitors =  Safe_Harbor, 
                            keep_flags = T, 
                            var = c("PRCP", "TAVG", "TMAX", "TMIN"))

# autoplot plots from first to last date, ignoring gaps
obs_covr <- meteo_coverage(meteo_df = dat)
autoplot(obs_covr)

# Alternative plot, showing gaps
# unique dates
min_date <- min(dat$date)
max_date <- max(dat$date)
dates <- data.frame(date = as.Date(x = seq.Date(from = min_date,
to = max_date, 
by = 'day')))
# join the original data to all the unique dates
temp <- dplyr::full_join(x = dates,
y = dat,
by='date')
temp$location <- Safe_Harbor

# dummy column for plotting
temp$size <- NA
temp$size[which(!is.na(temp$prcp))] <- 1

# plot with gaps in coverage
ggplot(temp, aes(x = date, y = location, size = size))+
   theme_bw()+
   geom_line(show.legend = F)
sckott commented 5 years ago

Thanks for the issue @filups - Sorry for any confusion: this is a great place to open issues regarding bugs, features, use cases, etc. Not just bug reports.

@geanders do you have any thoughts on this? plotting stuff is not one of my skills, and you were the original author of this i think

it makes sense to me to make this change to account for gaps

sckott commented 5 years ago

@filups if you have time, could you send a pull request with your proposed changes?

philipshirk commented 5 years ago

I'll see what I can do. Could you save me a bit of time by pointing me towards where I can find the code for the autoplot function and some info on the meteo_coverage output structure?

sckott commented 5 years ago

great, thanks.

autoplot.meteo_coverage is in https://github.com/ropensci/rnoaa/blob/master/R/meteo-autoplot.R

meteo_coverage is in https://github.com/ropensci/rnoaa/blob/master/R/meteo_utils.r

philipshirk commented 4 years ago

I (finally) started working on this, but I'm not sure if I can stay within the confines of the meteo_coverage class. What can you tell me about that class? Is it used for anything other than the autoplot.meteo_coverage function? My initial thought is to change the output of the meteo_coverage function from a data.frame to a list that contains the current data.frame output as well as a 2nd data.frame that I'll use for plotting in the autoplot.meteo_coverage.

sckott commented 4 years ago

@philipshirk Great, glad to hear it. Looks like meteo_coverage is only used for autoplot - so we are free to change it outputs