SymbolixAU / mapdeck

R interface to Deck.gl and Mapbox
https://symbolixau.github.io/mapdeck/articles/mapdeck.html
362 stars 40 forks source link

Fill opacity changes when setting stroke opacity #131

Closed symbalex closed 5 years ago

symbalex commented 5 years ago

The fill opacity in add_sf doesn't seem to be changing until the stroke opacity is set. It appears that fill opacity argument is not working properly.

Minimal example:

token <- "my token"

library(sf)
library(mapdeck)
sf_example <- geojsonsf::geojson_sf("https://symbolixau.github.io/data/geojson/SA2_2016_VIC.json")

mapdeck(mapdeck::mapdeck_style("light")
        , token = token) %>% 
  add_sf(layer_id = "example"
         , data = sf_example
         , fill_colour = "SA2_NAME16"
         , fill_opacity = 255
  )

screen shot 2019-03-06 at 10 41 35

mapdeck(mapdeck::mapdeck_style("light")
        , token = token) %>% 
  add_sf(layer_id = "example"
         , data = sf_example
         , fill_colour = "SA2_NAME16"
         , fill_opacity = 255
         , stroke_colour = "#000000"
         , stroke_opacity = 255
  )

screen shot 2019-03-06 at 10 42 04

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.5

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

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

other attached packages:
[1] mapdeck_0.2.1001 sf_0.6-3        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0                pillar_1.3.1              compiler_3.5.1            plyr_1.8.4                bindr_0.1.1              
 [6] class_7.3-14              tools_3.5.1               digest_0.6.18             jsonlite_1.6              tibble_1.4.2             
[11] gtable_0.2.0              pkgconfig_2.0.2           rlang_0.3.1               english_1.1-4             DBI_1.0.0                
[16] rstudioapi_0.7            yaml_2.2.0                curl_3.3                  bindrcpp_0.2.2            spData_0.2.9.0           
[21] e1071_1.6-8               dplyr_0.7.6               symbolix.utils_0.1.0.0003 fs_1.2.6                  htmlwidgets_1.3          
[26] classInt_0.2-3            grid_3.5.1                tidyselect_0.2.4          glue_1.3.0                data.table_1.12.1        
[31] geojsonsf_1.3.0001        R6_2.4.0                  jsonify_0.2.1             ggplot2_3.1.0             purrr_0.2.5              
[36] magrittr_1.5              scales_1.0.0              htmltools_0.3.6           units_0.6-0               assertthat_0.2.0         
[41] colorspace_1.3-2          lazyeval_0.2.1            munsell_0.5.0             crayon_1.3.4    

Using the most recent dev version of mapdeck.

SymbolixAU commented 5 years ago

In the first plot you're using fill_opacity = 255, where 255 is the maximum opacity.

If you set it to 100 you get transparency

mapdeck(mapdeck::mapdeck_style("light")
        , token = token) %>% 
  add_sf(layer_id = "example"
         , data = sf_example
         , fill_colour = "SA2_NAME16"
         , fill_opacity = 100
  )

screen shot 2019-03-06 at 11 28 50 am

However, I don't know why one of your plots is brighter than the other.

Also, you haven't set the style correctly. You need to use the argument name style =

symbalex commented 5 years ago

Thanks, didn't notice the style argument problem.

In the first plot you're using fill_opacity = 255, where 255 is the maximum opacity. If you set it to 100 you get transparency ... However, I don't know why one of your plots is brighter than the other

I think the brightness problem is the opacity. In the second plot, I think it is correctly using fill_opacity = 255. In the first plot, I think it is not recognising fill_opacity = 255 and using some default setting. Sorry if that was unclear before.

SymbolixAU commented 5 years ago

I took your first example and used fill_opacity = 100 to show it working.

symbalex commented 5 years ago

Gotcha. Hmm, OK, that's weird 🙃