Home > Software design >  Change color palette in e_visual_map from echart4r
Change color palette in e_visual_map from echart4r

Time:08-27

Is it possible to change the colour palette using the function e_visual_map from the package echart4r.

The default is the following.

library(tidyverse)
library(echarts4r)
data(mtcars)

mtcars |>
  e_charts(mpg) |>
  e_scatter(wt, qsec, scale = e_scale) |>
  e_visual_map(qsec, scale = e_scale)

enter image description here For example, is it possible to use the Viridis colour palette from the package ggplot2?

enter image description here

CodePudding user response:

You can add color as an additional argument, then you can input viridis as the parameter. Or you can put in a list of colors (e.g., color = c("#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072")).

library(tidyverse)
library(echarts4r)
library(viridis)

mtcars |>
    e_charts(mpg) |>
    e_scatter(wt, qsec, scale = e_scale) |>
    e_visual_map(qsec, scale = e_scale, color = viridis(5))

enter image description here

  • Related