Closed turgut090 closed 5 years ago
I should document e_add
better. It will add the column(s) named passed as children of the param
argument.
What you want is:
itemStyle :{
color:'blue'
}
Hence the column should be color
and not colors
. Thanks to issue #58 You can now inspect the json constructed by echarts4r
with e_inspect
; it can help when exploring such arguments.
In brief, this will work.
df = tibble(letter=LETTERS[1:5],
values = c(-1,-5,5,-1,3),
color = ifelse(values >0, 'green','blue'))
df %>%
e_charts(letter) %>%
e_bar(values) %>%
e_add("itemStyle", color)
Got it, thank you for the explanation
But why legend does not work properly
Is it possible to add there 2 labels: 1 for blue and 1 for green?
Also, it seems not working for polar coordinates. Please see the example and error messages below.
df = tibble(letter=LETTERS[1:5],
values = c(-1,-5,5,-1,3),
colors = if_else(values >0, 'green','blue'))
df %>%
e_charts(letter) %>%
e_polar() %>%
e_angle_axis() %>%
e_radius_axis(letter) %>%
e_bar(values, coord_system = "polar") %>%
e_add("itemStyle", color)
Error: Can't subset columns that don't exist.
x Column color
doesn't exist.
Run rlang::last_error()
to see where the error occurred.
I'm not sure I see the advantage of specifying every bar colour individually instead of using convenient groups.
library(echarts4r)
df <- tibble::tibble(letter=LETTERS[1:5],
values = c(-1,-5,5,-1,3),
color = ifelse(values >0, 'green','blue'))
df %>%
group_by(color) %>%
e_charts(letter) %>%
e_bar(values, stack = T) %>%
e_color(c("blue", "red"))
@zhiiiyang I will look into the issue of polar axis tomorrow.
I am new to echarts4r so not really sure about what convenient groups mean even after a quick search. If it helps, what I originally have in mind is to re-create a ring plot of several bars just like something like Apple Watch fitness rings colored by categories. Thank you for looking into it and please take your time.
How to set different colors for
e_bar
?I thought I might be able to reproduce bar_chart like funnel: