Created
September 26, 2023 23:47
-
-
Save helgasoft/82ca8e310932cc3549a48363d9920418 to your computer and use it in GitHub Desktop.
R | ECharts | dataset columns referenced in two series
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(22) | |
data <- tibble(x = 2 * pi * (1:100)/100) |> | |
mutate( | |
y1_bar = 0.5 * (sin(x)) + 1, | |
y2_bar = 0.5 * (sin(x)) - 1, | |
deltaY1 = rnorm(100, sd = 0.1), | |
deltaY2 = rnorm(100, sd = 0.1), | |
y1 = y1_bar + deltaY1, | |
y2 = y2_bar + deltaY2, | |
sizeY1 = abs(deltaY1), | |
sizeY2 = abs(deltaY2), | |
# Top series should be teal & black | |
colorY1 = case_when(y1_bar < y1 ~ "#008080", TRUE ~ "black"), | |
# Bottom series should be magenta & black | |
colorY2 = case_when(y2_bar < y2 ~ "#AA00AA", TRUE ~ "black")) | |
remotes::install_github('helgasoft/echarty') # v.1.6.0.01 | |
library(echarty) | |
data |> ec.init( yAxis= list(name='y'), legend= list(show=T)) |> | |
ec.upd({ # update presets | |
series[[1]] <- list(type= "scatter", name= 'y1', | |
encode= list(x='x', y='y1'), | |
symbolSize= ec.clmn('sizeY1', scale=100), | |
itemStyle= list(color= ec.clmn('colorY1')) ) | |
series[[2]] <- list(type= "scatter", name= 'y2', | |
encode= list(x='x', y='y2'), | |
symbolSize= ec.clmn('sizeY2', scale=100), | |
itemStyle= list(color= ec.clmn('colorY2')) ) | |
}) | |
# If you like echarty, please consider granting a Github star ⭐. |
Thanks for posting this. I've recently been trying echarts4r as a fast way to prototype echarts on the Shiny side of an app before implementing them client-side in React. For more complex graphs I ended up doing more troubleshooting than I'd have liked. I'll definitely take a look at echarty for this. Thanks again.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@stuvet, above is your example made with echarty.
