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

Duplicated colors when plotting more than 16 discrete colors #482

Open
smiller-usgs opened this issue May 8, 2024 · 0 comments
Open

Duplicated colors when plotting more than 16 discrete colors #482

smiller-usgs opened this issue May 8, 2024 · 0 comments

Comments

@smiller-usgs
Copy link

smiller-usgs commented May 8, 2024

When I try to plot more than 16 colors, the first and last colors in the legend do not show on the points on the map. The map points take on the colors of the second and second to last colors of the legend, respectively, resulting in duplicated colors.

library(mapview)
library(dplyr)
mybrew16 <- breweries %>% group_by(village) %>% summarise(n=n()) %>% arrange(desc(n)) %>% slice(1:16)

topbrews16 <- breweries %>% filter(village %in% mybrew16$village)

colors16 <- c("#F0A0FF", "#0075DC", "#993F00", "#4C005C", "#191919", "#005C31", "#2BCE48",
              "#FFCC99", "#808080", "#94FFB5", "#8F7C00", "#9DCC00", "#C20088", "#003380","#FFA405", "#FFA8BB")
mapview(topbrews16,zcol='village',col.regions=colors16,alpha.regions=1)

mybrew17 <- breweries %>% group_by(village) %>% summarise(n=n()) %>% arrange(desc(n)) %>% slice(1:17)

topbrews17 <- breweries %>% filter(village %in% mybrew17$village)

colors17 <- c("#F0A0FF", "#0075DC", "#993F00", "#4C005C", "#191919", "#005C31", "#2BCE48",
              "#FFCC99", "#808080", "#94FFB5", "#8F7C00", "#9DCC00", "#C20088", "#003380","#FFA405", "#FFA8BB","#426600")
mapview(topbrews17,zcol='village',col.regions=colors17,alpha.regions=1)

mybrew18 <- breweries %>% group_by(village) %>% summarise(n=n()) %>% arrange(desc(n)) %>% slice(1:18)

topbrews18 <- breweries %>% filter(village %in% mybrew18$village)

colors18 <- c("#F0A0FF", "#0075DC", "#993F00", "#4C005C", "#191919", "#005C31", "#2BCE48",
              "#FFCC99", "#808080", "#94FFB5", "#8F7C00", "#9DCC00", "#C20088", "#003380","#FFA405", "#FFA8BB","#426600","#FF0010")
mapview(topbrews18,zcol='village',col.regions=colors18,alpha.regions=1)

mybrew19 <- breweries %>% group_by(village) %>% summarise(n=n()) %>% arrange(desc(n)) %>% slice(1:19)

topbrews19 <- breweries %>% filter(village %in% mybrew19$village)

colors19 <- c("#F0A0FF", "#0075DC", "#993F00", "#4C005C", "#191919", "#005C31", "#2BCE48",
              "#FFCC99", "#808080", "#94FFB5", "#8F7C00", "#9DCC00", "#C20088", "#003380",
              "#FFA405", "#FFA8BB","#426600","#FF0010","#5EF1F2" )
mapview(topbrews19,zcol='village',col.regions=colors19,alpha.regions=1)

16colors

17colors

sessionInfo()
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default


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

time zone: America/New_York
tzcode source: internal

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

other attached packages:
[1] dplyr_1.1.4    mapview_2.11.2

loaded via a namespace (and not attached):
 [1] s2_1.1.6                utf8_1.2.4             
 [3] generics_0.1.3          class_7.3-22           
 [5] KernSmooth_2.23-22      lattice_0.22-5         
 [7] digest_0.6.34           magrittr_2.0.3         
 [9] grid_4.3.1              fastmap_1.1.1          
[11] jsonlite_1.8.8          e1071_1.7-14           
[13] DBI_1.2.2               fansi_1.0.6            
[15] crosstalk_1.2.1         scales_1.3.0           
[17] codetools_0.2-19        jquerylib_0.1.4        
[19] cli_3.6.2               rlang_1.1.3            
[21] units_0.8-5             ellipsis_0.3.2         
[23] munsell_0.5.0           base64enc_0.1-3        
[25] tools_4.3.1             raster_3.6-26          
[27] colorspace_2.1-0        vctrs_0.6.5            
[29] R6_2.5.1                png_0.1-8              
[31] stats4_4.3.1            proxy_0.4-27           
[33] lifecycle_1.0.4         classInt_0.4-10        
[35] leaflet_2.2.1           leaflet.providers_2.0.0
[37] htmlwidgets_1.6.4       pkgconfig_2.0.3        
[39] terra_1.7-71            pillar_1.9.0           
[41] glue_1.7.0              Rcpp_1.0.12            
[43] sf_1.0-15               tibble_3.2.1           
[45] tidyselect_1.2.1        rstudioapi_0.15.0      
[47] farver_2.1.1            htmltools_0.5.7        
[49] leafem_0.2.3            wk_0.9.1               
[51] satellite_1.0.5         compiler_4.3.1         
[53] sp_2.1-3   
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