Skip to content

Instantly share code, notes, and snippets.

@helgasoft
Created September 26, 2023 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgasoft/82ca8e310932cc3549a48363d9920418 to your computer and use it in GitHub Desktop.
Save helgasoft/82ca8e310932cc3549a48363d9920418 to your computer and use it in GitHub Desktop.
R | ECharts | dataset columns referenced in two series
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 ⭐.
@helgasoft
Copy link
Author

helgasoft commented Sep 26, 2023

@stuvet, above is your example made with echarty.
image

@stuvet
Copy link

stuvet commented Sep 27, 2023

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