Closed alexkrohn closed 11 months ago
Hi Alex,
Thanks for bringing this to our attention and for the reprex. The issue here is that the finalized plot produced by tess_ggplot()
is actually two gridded plots which are combined using cowplot::plot_grid()
, one for the base plot and one for the custom legend. This is why no additional ggplot functions can be added.
I’ve added a new argument to the tess_ggplot()
function, list
, which will return a list of two elements. Each element in the list is a ggplot object: one for the base plot and one for the legend.
Using your reprex objects as an example, you can now add your additional ggplot functions on to the base plot like so:
plot <-
tess_ggplot(krig_raster, plot_axes = TRUE, list = TRUE)
# Add in your polygon:
modplot <-
plot$plot +
geom_polygon(data = state.boundaries, aes(x = long, y = lat), color = "black")
# And add in the legend:
library(cowplot)
cowplot::plot_grid(modplot,
plot$legend,
rel_widths = c(3, 1))
Note that the custom legend is only created if plot_method
is set to "allQ"
or "maxQ"
; for "maxQ_poly"
and "allQ_poly"
a ggplot object is already produced by the function, so you can do:
tess_ggplot(krig_raster, plot_axes = TRUE, plot_method = “maxQ”) +
geom_polygon(data = state.boundaries, aes(x = long, y = lat), color = "black")
Thanks again for submitting this as an issue and let us know if you run into any additional problems.
That resolved the issue. Thank you!
(And go bears!)
Hi there! I really appreciate the package you've put out. Thanks so much for compiling all these great packages together into this easy to use framework.
I was wondering if you might explain how to plot polygons (ideally
sf
objects) onto yourtess_ggplot()
objects. Basically, I'd like to plot polygons for reference on top of the raster layer generated bytess_krig
.Here's a reproducible example:
Is there an easy way to get
sf
(ideally) or other polygons to print on top of the raster fromtess_ggplot
? This functionality seems to work well withggplot_gd
fromwingen
.(edited to add sf polygon example too)