-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aesthetic mapping in echarts4r legend #631
Comments
Your approach is technically correct but coloring things like this do not affect the legend, it's on echarts.js end. Does the code below fix your issue? ptd_data <- data.frame(
x = seq.Date(from = as.Date("2021-01-01"), by = "month", length.out = 12),
y = rnorm(12, 100, 10),
upl = rnorm(12, 110, 10),
lpl = rnorm(12, 90, 10),
point_type = sample(c("point_type_1", "point_type_2", "point_type_3", "point_type_4"), 12, replace = TRUE)
)
colours <- list(
"point_type_1" = "grey90",
"point_type_2" = "#361475",
"point_type_3" = "#fab428",
"point_type_4" = "#289de0"
)
ptd_data <- ptd_data %>%
mutate(point_colour = sapply(point_type, function(pt) colours[[pt]]))
points <- ptd_data %>%
group_by(point_type)
ptd_data %>%
e_charts(x) %>%
e_line(serie = y,
symbol = "none"
,symbolSize = 4
,emphasis = list(
scale = 2 # Enable scaling
)
) %>%
e_data(points, x) %>%
e_scatter(y, symbol_size = 20L) %>%
e_tooltip(trigger = "axis") %>%
e_color(
c("blue", colours |> unlist() |> unname(), colours |> unlist() |> unname())
) |
Thankyou John! That does work for the legend. Unfortunately as a result of having to layer e_scatter over e_line in this way we lose a lot of the visual appeal of the line chart, with the line going through the points and no option for the empty circle. Not sure if there is any way we can amend this? I managed to kind of hack the legend using e_visual_map as per below but obviously this doesn't fit as neatly and doesn't have series control. library(dplyr) color_mapping <- list( ptd_data <- data.frame( ptd_data <- ptd_data %>% ptd_data %>% |
Hi,
I have a need to plot a single time series using echarts4r.
I have been able to plot the desired output using the below
however as you can see the legend doesn't follow suit in terms of the e_add_nested color mapping
Desired output can be demonstrated using ggplot2 using the aes color mapping which splits the legend accordingly
Is there a solution using e charts4r
The text was updated successfully, but these errors were encountered: