Search code examples
recharts4r

Scale is not applied in e_scatter


I have this code:

library(echarts4r)

df_1 <- data.frame(
  EIXOX = 1:100,
  VAR1 = 200:101,
  VAR2 = 201:300,
  VAR3 = 301:400,
  VAR4 = 401:500
)

my_scale <- function(x) scales::rescale(x, to = c(5, 45))

df_1 |>
  e_chart(x = EIXOX, height = 250) |>
  e_scatter(serie = VAR1, legend = FALSE, scale = my_scale) 

But the size of the points is the same, they do not change when the x axis advances. How to adjust this?

I need to keep y and x in their places.


Solution

  • You have to map a column on size=. However, that does not work when using the variable already mapped on y (or I miss something). Fro that reason I added a helper column with a different name:

    library(echarts4r)
    
    df_1 <- data.frame(
      EIXOX = 1:100,
      VAR1 = 200:101,
      VAR2 = 201:300,
      VAR3 = 301:400,
      VAR4 = 401:500
    )
    
    my_scale <- function(x) scales::rescale(x, to = c(5, 45))
    
    df_1 |>
      transform(VAR1_size = VAR1) |> 
      e_charts(EIXOX) |>
      e_scatter(VAR1, VAR1_size, legend = FALSE, scale = my_scale)