Skip to content

Instantly share code, notes, and snippets.

@helgasoft
Last active May 30, 2024 19:47
Show Gist options
  • Save helgasoft/e914fe6f4a9ed9407f78e41cb18b3aaa to your computer and use it in GitHub Desktop.
Save helgasoft/e914fe6f4a9ed9407f78e41cb18b3aaa to your computer and use it in GitHub Desktop.
echarty announcements and temporary notes
#' This gist is for echarty announcements and notes
#' Comments are temporary, periodically deleted.
#' If you like echarty, please consider granting a Github star ⭐.
library(echarty)
data.frame(x = seq.int(1, 5, 1),
y = seq.int(1, 10, 2)) |>
ec.init(
series.param= list(
type='line', symbolSize= 10,
lineStyle = list(opacity= 0.7),
itemStyle = list(opacity= 1),
areaStyle= list(color= 'red', opacity= 0.5))
)
@helgasoft
Copy link
Author

dynamically defined stacked bars, for @enriquepravia

df <- data.frame(
  grp= rep(LETTERS[1:5]), c1= runif(5), c2= runif(5), c3= runif(5)
)
df |> echarty::ec.init(
  legend= list(show=T), yAxis= list(name=''),
  series= lapply(2:length(colnames(df)), \(i) {
    list(type='bar', stack= 'stk', encode= list(y=i), name= colnames(df)[i])
  })
)

image

@helgasoft
Copy link
Author

@joekeane7, symbol coloring could be done with visualMap categories (instead of pieces)

library(echarty); library(dplyr)
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)
)

ptd_data |> ec.init(
  series.param = list(type='line', name='line', symbolSize=12),
  legend= list(show=T),
  visualMap= list(
    dimension= 5,  # R-count
    left= "center", bottom= "5%", orient= "horizontal", itemSymbol= "circle",
    categories= sort(unique(ptd_data$point_type)),
    inRange= list(color= c("grey", "#361475", "#fab428", "#289de0"))
  ),
  tooltip= list(trigger= "axis")
)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment