pbs-assess / pacea

An R package to house Pacific Region ecosystem data to help facilitate an ecosystem approach to fisheries.
Other
14 stars 0 forks source link

Plotting functions - ideas #14

Closed travistai2 closed 11 months ago

travistai2 commented 1 year ago

Temporal

Line graphs for non-spatial data (e.g. PDO) can be plotted using the native base plot() function. For multipanel plots (e.g. multiple time series), base graphics could be used with a for loop to generate a faceted panel. Or ggplot could be used, but this would create a dependency on ggplot2

Spatial

Any spatial plots requires a dependency on a spatial package (e.g. sf, terra). The plot() function in sf overrides base graphics plot and spatial objects can be easily plotted. Help file should walk through steps to plot a single climatology. Vignette or built in function could produce panel plot of 10-20 year mean climatologies can be plotted for long term trends and visualization (e.g. 4 panel plot of the last four decades of SST data). Possibly even an animation.

Decide on whether to store spatial data as a dataframe or spatial object (e.g. raster). Then would need to create function to either convert dataframe into a raster for visualization, or a function to convert a raster stack into a dataframe (more user friendly)

andrew-edwards commented 1 year ago

For non-spatial, I'll try something first for the oni data set. Am thinking of calling it a pacea_t (for temporal) class, and then creating a plot.pacea_t() function which will over-write the native plot(), and take care of converting the dates into something usable.

seananderson commented 1 year ago

For what it's worth, sf already has ggplot2 in 'Suggests' and it's probably fairly rare to have a user without ggplot2 already installed. It might be worth just going that route rather than fighting with everything involved in nicely laid out automated multi panel base graphics. If you want to get fancy, you could include it in Suggests and conditionally check for it (requireNamespace("ggplot2", quietly = TRUE)) in the plotting functions so the user can install the package and grab data without ggplot2.

andrew-edwards commented 1 year ago

Thanks Sean. Trying to avoid a house-of-cards of package dependencies. But may be hard to avoid sf completely (and hence ggplot2), and, yes, ggplot2 is fairly ubiquitous. Also, I still don't know ggplot2 that well, but I'm only playing with simpler plots for now....

travistai2 commented 1 year ago

Thanks Sean. Indeed, that's along the lines of what I was thinking. If we store data as sf objects, they are still a nice dataframe format for users--layers (e.g. monthly climatologies) in columns, and the gridded data and geometry in rows. plot() also works for sf objects without loading the sf package--note, plotting data converted as sf points is faster (although not visually 'gridded') and marginally smaller in size than data converted to sf polygons.

I don't think wrangling with base graphics is worth the time for exploratory multipanel plotting. Using ggplot2 makes sense for making plotting functions within the package.

andrew-edwards commented 11 months ago

Think we've figured this one out between us.