Skip to content

Instantly share code, notes, and snippets.

@helgasoft
Last active July 29, 2021 18:27
Show Gist options
  • Select an option

  • Save helgasoft/badeee138724d92e647895eb3d4b8d0f to your computer and use it in GitHub Desktop.

Select an option

Save helgasoft/badeee138724d92e647895eb3d4b8d0f to your computer and use it in GitHub Desktop.
R | Echarts | gauge undocumented
# Undocumented feature found for 'gauge' in ECharts (https://echarts.apache.org/en/option.html#series-gauge.type)
# Attribute 'encode' is not even mentioned in the docs, but could be used when 'dataset' is present.
# All columns listed in 'encode' (like x,y,z) are ignored and first remaining dataset column becomes gauge data.
# In example below this 'first remaining' column is 'circumference'. Neat!?
library(echarty); library(dplyr)
df <- Orange %>% filter(age==1582) %>% mutate(Tree=as.character(Tree))
clr <- c("#eeb422","#382278","#d9534f",'magenta','red')
p <- df %>% group_by(Tree) %>% ec.init( preset=FALSE,
tl.series = list(
type='gauge', axisLine=list(lineStyle=list(width=15)),
max = 300, # or max(df$circumference),
encode=list(x='Tree', y='age')
))
i <- 0 # set series colors in options generated
p$x$opts$options <- lapply(p$x$opts$options, function(x) {
i <<- i+1
x$series[[1]]$axisLine$lineStyle$color <- list(
c(0.25, 'green'),
c(1, clr[i])); x })
p
@helgasoft

Copy link
Copy Markdown
Author

idea from @rdatasculptor

image

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