Last active
July 29, 2021 18:27
-
-
Save helgasoft/badeee138724d92e647895eb3d4b8d0f to your computer and use it in GitHub Desktop.
R | Echarts | gauge undocumented
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
| # 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
idea from @rdatasculptor