Ian.T
Ian.T

Reputation: 1166

Change color palette in e_visual_map from echart4r

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

Upvotes: 1

Views: 336

Answers (1)

AndrewGB
AndrewGB

Reputation: 16856

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

Upvotes: 2

Related Questions