Rayshader, how to prevent that plot_gg displays edges of polygons

251 Views Asked by At

I want to map the amount of inhabitants of the Netherlands in 500x500 m squares with plot_gg from the Rayshader package. Plotting 2D with ggplot works fine but plot_gg shows the edges of every 500x500 m polygon and I cannot find a way to disable/hide (not show) that. I think I have tried all arguments of plot_gg but to no success.

This is my (hopefully) reproducible code:

library(ggplot2)
library(rayshader)
library(sf)    

temp <- tempfile()
download.file("https://www.cbs.nl/-/media/cbs/dossiers/nederland-regionaal/vierkanten/500/2022-cbs_vk500_2021_v1.zip", temp)
NLD <- read_sf(utils::unzip(temp, "cbs_vk500_2021_v1.gpkg"))

NLD <- NLD[-c(99:nrow(NLD)),]                # for testing (faster)

NLD$aantal_inwoners <- ifelse(NLD$aantal_inwoners < 0, 1, NLD$aantal_inwoners)

kaart <- ggplot(NLD)+
  geom_sf(aes(fill=aantal_inwoners), colour=NA) +
  scale_fill_gradient(high="deeppink", low="black") + 
  theme_void() +
  theme(legend.position = "none")

#This second part is required to keep a white background in plot_gg (otherwise it is black). 
kaart <- kaart + theme(panel.background = element_rect(fill="white", color="white"),        
                       plot.background = element_rect(fill = "white", color="white"))

kaart

plot_gg(kaart, width = 3, height = 3, multicore = TRUE, 
        zoom = .7, theta = 0, phi = 90, windowsize = c(800, 800)) 

This is what I get from ggplot:

ggplot output of first 99 rows

And this is what plot_gg shows, I dont want the squares to be displayed:

plot gg

Those polygons do touch according to st_touches(NLD$geom) so I don't expect that to be the problem.

Output of SessionInfo():

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=English_Netherlands.utf8  LC_CTYPE=English_Netherlands.utf8    LC_MONETARY=English_Netherlands.utf8
[4] LC_NUMERIC=C                         LC_TIME=English_Netherlands.utf8    

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

other attached packages:
[1] filesstrings_3.2.3 stringr_1.5.0      sf_1.0-9           rayshader_0.32.7   ggplot2_3.4.0     

loaded via a namespace (and not attached):
 [1] rgl_0.110.2        Rcpp_1.0.9         prettyunits_1.1.1  png_0.1-8          class_7.3-20       assertthat_0.2.1   digest_0.6.31     
 [8] foreach_1.5.2      utf8_1.2.2         R6_2.5.1           e1071_1.7-12       pillar_1.8.1       rlang_1.0.6        progress_1.2.2    
[15] rstudioapi_0.14    extrafontdb_1.0    magick_2.7.3       textshaping_0.3.6  extrafont_0.18     htmlwidgets_1.6.1  munsell_0.5.0     
[22] proxy_0.4-27       compiler_4.2.2     xfun_0.36          pkgconfig_2.0.3    systemfonts_1.0.4  base64enc_0.1-3    htmltools_0.5.4   
[29] tidyselect_1.2.0   tibble_3.1.8       rayrender_0.29.0   codetools_0.2-18   fansi_1.0.3        crayon_1.5.2       dplyr_1.0.10      
[36] withr_2.5.0        grid_4.2.2         jsonlite_1.8.4     Rttf2pt1_1.3.11    gtable_0.3.1       lifecycle_1.0.3    DBI_1.1.3         
[43] magrittr_2.0.3     units_0.8-1        scales_1.2.1       KernSmooth_2.23-20 cli_3.4.1          stringi_1.7.8      farver_2.1.1      
[50] doParallel_1.0.17  terrainmeshr_0.1.0 ellipsis_0.3.2     ragg_1.2.5         generics_0.1.3     vctrs_0.5.1        iterators_1.0.14  
[57] tools_4.2.2        glue_1.6.2         rayimage_0.7.4     purrr_1.0.1        hms_1.1.2          parallel_4.2.2     fastmap_1.1.0     
[64] colorspace_2.0-3   strex_1.4.4        classInt_0.4-8     knitr_1.41        

For completeness, this is the output of the entire dataset (for inhabitants (inwoners in Dutch)). In plot_gg I get that ugly raster over it:

ggplot NL plot_gg

0

There are 0 best solutions below