Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding stippling with tm_lines before tm_facets results in facet data from one facet overwriting all others #855

Open
LenLon opened this issue Apr 4, 2024 · 0 comments

Comments

@LenLon
Copy link

LenLon commented Apr 4, 2024

Sorry for the long-winded title, easier to describe what is happening with images.

This is the base plot I am working from, with code working as expected:

grafik

  tm_fill(col = "grey") +
  tm_shape(filter(GS_cli_all_aez_20yr_changes_plot, year != 2005 & season == "first"),
           bbox = tmaptools::bb(matrix(c(8.5, 1.7, 16.5, 13.2), 2, 2))) + 
  tm_graticules(x = c(8, 10, 12, 14, 16), 
                y = c(2, 4, 6, 8, 10, 12), 
                alpha = 0.4) +  
  tm_fill("GS_meanT_abs", midpoint = 0, 
          style = "cont",
          title = "Change in 20-year r.m. GS mean temperature compared to baseline [°C]",
          palette = "-RdYlBu", 
          legend.is.portrait = FALSE) + 
  #tm_shape(filter(GS_cli_all_stipple,
  #               GS_meanT_abs_sign_test == 1 & year != 2005 & season == "first")) + 
  #tm_lines(alpha = 0.5) +
  tm_facets(by = c("scenario", "year")) +
  tm_shape(CM_AEZ) +                                                              
  tm_borders(lwd = 1, lty = 2) +                                                  
  tm_shape(cameroon_admin[1,]) +                                                  
  tm_borders(lwd = 1, col = "black") +                                                                             
  tm_shape(CM_AEZ) +                                                              
  tm_text("Zone", xmod = c(0, -0.5, 0, 0, 0.3), size = 1) +                                          
  tm_layout(legend.outside = TRUE,
            legend.title.size = 0.9,
            legend.text.size = 0.8,
            legend.format = list(fun=function(x) formatC(x, digits=0, format="f")),
            legend.outside.position = "bottom", 
            legend.outside.size = 0.15,
            panel.label.bg.color = "white", 
            panel.label.size = 1.2,
            panel.labels = list(rows = c("SSP1-2.6", "SSP3-7.0"),
                                columns = c("2030", "2050", "2090"))); meanT_abs

Now I want to add a shape layer with stippling I generated using the HatchedPolygons package. The code is the same, the lines commented out above added back in is the only difference). It correctly plots over the facets, but the base layer (the temperature changes plotted using tm_fill) is now comprised of the SSP3-7.0/2090 facet in all facets:

grafik

There is no warning and this behaviour only happens when I put the tm_lines (and associated tm_shape) BEFORE the tm_facets call, if I put it after it plots the temperature changes correctly again but plots the same stippling on all facets (understandably). This seems like a bug to me, as I have no idea what would cause this in my code..

Addendum: This is what happens when I reverse the order (plot the stippling first, then the temperature changes with a low alpha on top). It seems like it doesn't apply the filtering anymore and plots all stippling geometries (I have a sf object with stippling at all grid points which gets filtered to the relevant variable or its robustness statistic), but facets the temperatures correctly.

grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant