Search code examples
rplotechartsecharts4r

Change annotation text color in echarts4r


I would like to change the color of the Text added with e_text_g() to the echarts4r plot.

example

library(echarts4r)
library(tidyverse)
data(cars)
cars

cars %>% count(speed) %>% 
  e_chart(speed) %>% 
  e_bar(n) %>% 
 e_text_g(style = list(text = c("Text i want like to change to red"), # change the color of the text
            fontSize = 20, opacity = .7, color = "red"), left = 75, top = 1) %>% 
            e_text_style(
            color = c("red")
          )



Solution

  • If you want to change the color of that added text with e_text_g() only you can do this by adding a fill argument,

    library(echarts4r)
    library(dplyr)
    data(cars)
    
    
    cars %>%
        count(speed) %>%
        e_chart(speed) %>%
        e_bar(n) %>%
        e_text_g(
            style = list(
                text = c("Text i want like to change to red"),
                fontSize = 20,
                opacity = .7,
                fill = "red" # changing color of this text
            ),
            left = 75,
            top = 1
        )