JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
585 stars 82 forks source link

Visual Map for colour does not appear to work as intended in e_geo/e_scatter #592

Open MrMisc opened 7 months ago

MrMisc commented 7 months ago

I would like to start off by saying I am very excited with ECharts, and I really want to try making some of my work flourish with some of the amazing controls and visuals from echarts (trying to come from plotly here).

I am genuinely having trouble understanding how visual_map is supposed to work. Consider the following with this dataset DirectExample.csv:

input<-read.csv("DirectExample.csv")
library(echarts4r)

my_scale <- function(x) scales::rescale(x, to = c(10,60))
my_2scale <- function(x) scales::rescale(x, to = c(0.01,100.00))
input|> arrange(desc(n)) |> group_by(Year)|>
  e_charts(lon,timeline = TRUE) |> 
  e_geo() |> 
  e_scatter(lat,n,bind = lethality, coord_system = "geo", name = "reports",rm_y = FALSE, rm_x = FALSE,scale = my_scale)|>
  e_visual_map(lethality,inRange = list(symbol = "diamond",colorLightness = c(0.6,0.3), colorHue = c(50,10),colorSaturation = c(100,200)),scale = my_2scale,dimension = 3,bottom = 300)|>  
  e_tooltip(formatter = htmlwidgets::JS("
      function(params){
        return('Number of Outbreak Incidents: ' + params.value[2] + '<br />%Lethality: ' + params.name*100)
      }
    "))|>
  e_theme("essos")|>

  e_animation(easing.update = 'quarticOut',easing = 'quarticOut')

My issue lies with the fact that the colouring of the scatterpoints does not follow the "lethality" column as expected. Instead, it appears to be following the n column, or perhaps something else. I want the size of the points to follow n, as they appear to be doing so, but I really would like someone's help in getting the colour of the points to follow what I have described in e_visual_map. Currently as it stands, for instance, Australia or Mongolia in 2005, appears to show a lighter scatterpoint than Turkey in 2005, which doesn't make sense to me since the lethality of those 2 points is 100% while that of in Turkey is only about 53.5%.

munoztd0 commented 6 months ago

Spent all morning on this, got really frustrated... this is one of the more broken things I ever seen I ever worked on.

No mather what you put as first argument of e_visual_map() it will only affect the scaling but the visual map filter will still affect the y data from the e_scatter...

I wrote that for the clean the formatter so I will gave it to you anyway:


    function(params) {
        var numb = params.name * 1;
        numb = numb.toFixed(2);

        var outbreakIncidents = params.value[2];

        // Check if params.value[2] is undefined
        if (outbreakIncidents === undefined) {
            return ''; // Return nothing if params.value[2] is undefined
        }

        return 'Number of Outbreak Incidents: ' + outbreakIncidents + '<br />%Lethality: ' + numb;
    }

But that won´t solve the real problem.