NOAA-OCM / SWMPrExtension

Functions for Analyzing and Plotting SWMP Estuary Monitoring Data from the NERR System archive at
http://cdmo.baruch.sc.edu/
Other
12 stars 5 forks source link

seasonal_dot error when lm_lab = TRUE #45

Closed DaveEslinger closed 4 years ago

DaveEslinger commented 5 years ago

It seems that having lm_lab = TRUE gives an error with the seasonal_dot function. This can be reproduced with the first exmple call in the help section:

#dat_wq <- subset(dat_wq, subset = c('2010-01-01 0:00', '2017-01-01 0:00'))
dat_wq <- qaqc(dat_wq, qaqc_keep = c(0, 3, 5))

x <-
  seasonal_dot(dat_wq, param = 'do_mgl'
               , lm_trend = TRUE
               , lm_lab = TRUE
               , plot_title = TRUE)

Give the error:

Error: Aesthetics must be either length 1 or the same as the data (144): label, fontface

I get this error on my work computer, Angel got it on his, but I don't seem to get it on my personal computer. I also note that the files that CDMO produce have been run with lm_lab = TRUE and seem to work fine. That makes me think it may be a missing font issue.

DaveEslinger commented 5 years ago

Helvetica Neue seems to be the default font. It is not a default Windows font for PCs, but appears to be default with Macs. No Helvetica fonts for PCs at all by default it appears. I suggest we change the default to Calibri, which is Microsoft's new default fancy sans sarif font.

Feedback or, ideally, suggestions for a platform independent font, are welcome!

swmpkim commented 4 years ago

This just happened to me too! Work computer, windows. It stopped my status report re-run in its tracks and I wish I'd taken a look here before tracking the error all the way back myself :-D . I'm okay with Calibri, or Arial, or anything that'll work everywhere.

swmpkim commented 4 years ago

Has Helvetica been the default the whole time? Because I have run through the entire status report process before and it didn't give me problems. I recently updated R and all my packages, but I don't think anything's changed in my Windows setup.

FWIW, here's sessionInfo() output:

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] SWMPrExtension_1.1.1 SWMPr_2.3.1          zoo_1.8-6            ggplot2_3.2.1  

ETA: Looks like the choices for ggplot fonts are just serif, sans, and mono. And then whatever is on your system gets used. See, e.g., https://stackoverflow.com/a/34610941

DaveEslinger commented 4 years ago

I think I've also been successful previously, so I wonder if it is something the RStudio and/or R changed in how they map default fonts. Just an idea at the moment.

swmpkim commented 4 years ago

Ooooh, it may have to do with faceting. From the ggplot2 3.2.0 news, under "breaking changes" (emphasis mine):

In some cases, ggplot2 now produces a warning or an error for code that previously produced plot output. In all these cases, the previous plot output was accidental, and the plotting code uses the ggplot2 API in a way that would lead to undefined behavior. Examples include a missing group aesthetic in geom_boxplot() (#3316), annotations across multiple facets (#3305), and not using aesthetic mappings when drawing ribbons with geom_ribbon() (#3318).

Edit: Discussion about the annotation issue: https://github.com/tidyverse/ggplot2/issues/3305

swmpkim commented 4 years ago

I still have R version 3.5.2 + ggplot2 version 3.1.0 on my computer and can confirm that seasonal_dot() with lm_lab = TRUE works just fine with my own data and the data in the example code. In the thread linked in my last comment, there was some discussion about including annotation labels in the data frame, and that sounds like it should work with the newer version of ggplot?

dat_wq <- elksmwq
dat_wq <- qaqc(dat_wq, qaqc_keep = c(0, 3, 5))
x <-
   seasonal_dot(dat_wq, param = 'do_mgl'
                , lm_trend = TRUE
                , lm_lab = TRUE
                , plot_title = TRUE)
x

R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] SWMPrExtension_0.3.16.9000 SWMPr_2.3.0               
[3] zoo_1.8-4                  ggplot2_3.1.0     
DaveEslinger commented 4 years ago

Closed back with v1.1.2