inbo / camtraptor

Camtraptor is an R package to read, explore and visualize Camera Trap Data Packages (Camtrap DP)
https://inbo.github.io/camtraptor/
MIT License
10 stars 2 forks source link

Give a special color to value 0 in visualization of all deployment features #34

Closed damianooldoni closed 2 years ago

damianooldoni commented 3 years ago

After meeting with @jimcasaer, we decided to give color black to value 0 in map_dep() as it is a special/sentinel value. This should affect the visualization of all features (rai, n_species, effort, n_obs)

damianooldoni commented 2 years ago

After breaking my head to add zero as special value as stated here, I came to the idea that actually it is not completely right to define 0 as a special value as all variables we want to visualize are continuous! The transitions should be smooth. So, it's just a matter of defining a specific color palette which starts from black.

We can use already predefined palettes with black as extreme value. These are:

We can otherwise make our own palette, not a big deal, just choosing the color we want to pass through, e.g. by passing palette_colors <- c("black", "green", "blue") to arg palette in leaflet::colorNumeric() function

@jimcasaer: give a look to examples below please and tell me which one do you like it most? Are you satisfied with one of these palettes?

"magma" color palette

Extreme values:

map_with_zero

Middle range values:

map_with_zero2

"inferno" color palette

Extreme values:

map_with_zero_inferno1

Middle range values:

map_with_zero_inferno2

A custom palette

Extreme values:

map_with_zero_custom1

Middle range values:

map_with_zero_custom2

damianooldoni commented 2 years ago

I think also that the choice of the palette should still be left to the user by adding the argument palette to map_dep(). @jimcasaer: the choice of the favourite palette (see comment above) is sitll important as we can use it as default palette.

damianooldoni commented 2 years ago

Update: I implemented my solution in #80 and merged to main branch so everybody can test it easily by installing the package. Default palette: "inferno".

jimcasaer commented 2 years ago

@damianooldoni sorry for the long delay before taking this up when do you have 5 minutes to discuss this before approving?

damianooldoni commented 2 years ago

We decided to try to get a second layer with only the zeros and those ones with a special marker or symbol. In this way are the zero values easily detectable.

damianooldoni commented 2 years ago

@jimcasaer: in #84 I tackled this issue again. Can you give a look to the results as shown in vignette: https://inbo.github.io/camtrapdp/articles/visualize-deployment-features.html

If you are satisfied with this kind of marker, we can close this issue and give a party 🥳

jimcasaer commented 2 years ago

hmm, the markers are very big !! and blur the total view of the map -- so to be honest: not yet fully satisfied no party time yet

what about using simple circle markers in a specific color for the subset of locations with "0" values

damianooldoni commented 2 years ago

Ok. So, the markers should be scalable like the other circles. Notice I leave the continuous scale in legend from 0 but the values mapped in the legend are all data without 0. This to allow visualizing values which are almost 0 but not 0.

Let's see what you prefer:

Option 1

gray circle markers, with stroke, default opacity

image

Option 2

gray circle markers, with stroke, fillOpacity = 0.8, opacity of the stroke = 0.8

image

Option 3

gray circle markers, without stroke, fillOpacity = 0.8

image

Option 4

black circle markers, with stroke, standard opacity

image

@jimcasaer: let me know which options you like at most, so I can provide you more examples. It's like selling a suit 😄

jimcasaer commented 2 years ago

@damianooldoni preference for option 4 -- only wondering if red or white would not be better given the background colours of the maps

the suit is almost sold, difficult client

damianooldoni commented 2 years ago

Let's give a try!

white - default opacity

default opacity is way too low, I think.

image

white - high opacity

Better, but it doesn't stand out, I think.

image

red - default opacity

image

red - high opacity

image

Personally I find red with high opacity the best one. But, be careful: it's the best one if we use default palette! If a user opts for example for `palette = "reds", I think making red circles is not the best option anymore.

Proposal: as we allow the user to pass a different palette than the default one, I strongly recommend to allow him/her to define also the color of these new circles if red is not good.

jimcasaer commented 2 years ago

damiano,

my personal preference is the red - default opacity :-) and yes I like the idea of to have a default palette and default red -- but allowing the user to indicate other palettes and other colours

damianooldoni commented 2 years ago

Great! I will do.

damianooldoni commented 2 years ago

@jimcasaer: done and merged to main in #86. Online documentation and vignette should be automatically updated on the website within few minutes. Let me know what do you think about it.

jimcasaer commented 2 years ago

could it be that the red inside/outside is reversed in comparison to example 3 ?

damianooldoni commented 2 years ago

I have just given a look to the leaflet maps in https://inbo.github.io/camtrapdp/articles/visualize-deployment-features.html It seems everything works as expected. The stroke is more opaque than the circle as expected. Or would you like less opacity of the inner circle in general?

jimcasaer commented 2 years ago

very strange -- my leaflet does the opposite -- when do you have 5 minutes ?

jimcasaer commented 2 years ago

works fine now outside of markdown -- :-) final ideas

damianooldoni commented 2 years ago

The cluster option already exists. By default is cluster = TRUE. You can deactivate clustering via cluster = FALSE. it's very easy to add clustering to cluster deployments with zero values as well.

But I would avoid to allow a mix behavior, i.e. cluster = TRUE for deploys with zero values and cluster = FALSE for all other deployments or viceversa. It will result in adding another argument to the function and I don't think you will ever user it. Do you agree on this?

damianooldoni commented 2 years ago

I think I misunderstood your request in my previous comment., @jimcasaer. We can cluster zero values deploys and non zero values deploys apart (as explained in my comment above, and as I will push on main in a while). But we can NOT cluster zero and non-zero values deploys together as they are two different layers, indeed.

A small but maybe important graphic decision.

Do you prefer non-zero deploys on top of zero ones (option 1):

image

Or viceversa (option 2)?

image

I think option 1, but I would like your opinion on this. Thanks.

damianooldoni commented 2 years ago

@jimcasaer: Pull Request #87 implements option 1 as described in my comment above. Give me your ok and I can push it to main.

jimcasaer commented 2 years ago

when do you have a moment looks like clustering is not working on both layers

damianooldoni commented 2 years ago

Well, @jimcasaer, it cannot work on main branch as I have still not pushed to main. Should I?

damianooldoni commented 2 years ago

after videocall with @jimcasaer we decided to go for option 1. Unfortunately the merged PR #87 implemented the worng option (option 2). A fast PR is following.

damianooldoni commented 2 years ago

@jimcasaer: does everything work fine now? I hope so. Please let me know. Hopefully we can close this issue.

jimcasaer commented 2 years ago

you can close it :-) good start for the weekend

damianooldoni commented 2 years ago

After @jimcasaer brainstorming with his colleagues, we decided to:

  1. add show not show argument (default: show)
  2. marker type (default = small cross)
  3. marker color (default = white)
damianooldoni commented 2 years ago

@jimcasaer:

  1. do you agree on the icon?
  2. which size? See examples from 10px up to 25px
  3. which color as default? Still white in mind?
library(dplyr)
library(camtrapdp)

# icon from https://icons8.com/icons/set/math
# red (E74C3C) - 10px
icons <- leaflet::icons(
  iconUrl = "https://img.icons8.com/ios-glyphs/30/E74C3C/multiply.png",
  iconWidth = 10,
  iconHeight = 10
)
leaflet::leaflet(mica$deployments) %>% 
  leaflet::addTiles() %>% 
  leaflet::addMarkers(icon = icons)
#> Assuming "longitude" and "latitude" are longitude and latitude, respectively

# black (000000)  - 15px
icons <- leaflet::icons(
  iconUrl = "https://img.icons8.com/ios-glyphs/30/000000/multiply.png",
  iconWidth = 15,
  iconHeight = 15
)
leaflet::leaflet(mica$deployments) %>% 
  leaflet::addTiles() %>% 
  leaflet::addMarkers(icon = icons)
#> Assuming "longitude" and "latitude" are longitude and latitude, respectively

# yellow (F1C40F)  - 20px
icons <- leaflet::icons(
  iconUrl = "https://img.icons8.com/ios-glyphs/30/F1C40F/multiply.png",
  iconWidth = 20,
  iconHeight = 20
)
leaflet::leaflet(mica$deployments) %>% 
  leaflet::addTiles() %>% 
  leaflet::addMarkers(icon = icons)
#> Assuming "longitude" and "latitude" are longitude and latitude, respectively

# white (FFFFFF)  - 25px
icons <- leaflet::icons(
  iconUrl = "https://img.icons8.com/ios-glyphs/30/FFFFFF/multiply.png",
  iconWidth = 25,
  iconHeight = 25
)
leaflet::leaflet(mica$deployments) %>% 
  leaflet::addTiles() %>% 
  leaflet::addMarkers(icon = icons)
#> Assuming "longitude" and "latitude" are longitude and latitude, respectively

Created on 2022-03-15 by the reprex package (v2.0.1)

jimcasaer commented 2 years ago

given the standard palette used in map_dep I would suggest to go for a default black and for the smallest symbol (and now I hope the female part of our team will agree :-) )

damianooldoni commented 2 years ago

Thanks a lot. Could you please check this with your team (or its female part of it) and give me the final GO?

jimcasaer commented 2 years ago

@damianooldoni cluster = FALSE seems to give an error when using map_dep

damianooldoni commented 2 years ago

Yes, you are right. I tried to change this

clusterOptions = if (cluster == TRUE) leaflet::markerClusterOptions() else NULL

with this:

clusterOptions = ifelse(cluster == TRUE,
                                leaflet::markerClusterOptions(),
                                NULL
        )

but R said NO 😄

I revert it and everything should look good again.

damianooldoni commented 2 years ago

Done in https://github.com/inbo/camtraptor/commit/7039d97445e699c2f8acccec7e6402d162ce4265 directly on main. Please reinstall and let me know.

jimcasaer commented 2 years ago

the result is great !! thanks adapted icon size to 5 Rplot_damiano