Skip to content

Instantly share code, notes, and snippets.

@helgasoft
Last active May 24, 2022 11:57
Show Gist options
  • Select an option

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

Select an option

Save helgasoft/793320ec9fa072c3e01a54c7fe56503f to your computer and use it in GitHub Desktop.
R | ECharts | use ec.clmn in endLabel formatter and in pictorialBar symbol
library(echarty); library(dplyr)
# set first column as X and second as Y to avoid explicitly define them later
mydf <- data.frame(
Date = c("2021-08-02", "2021-08-03", "2021-08-04", "2021-08-05", "2021-08-06", "2021-08-09", "2021-08-10", "2021-08-11", "2021-08-02", "2021-08-03", "2021-08-04", "2021-08-05", "2021-08-06", "2021-08-09", "2021-08-10", "2021-08-11", "2021-08-02", "2021-08-03", "2021-08-04", "2021-08-05", "2021-08-06", "2021-08-09", "2021-08-10", "2021-08-11", "2021-08-02", "2021-08-03", "2021-08-04", "2021-08-05", "2021-08-06", "2021-08-09", "2021-08-10", "2021-08-11"),
CasesPer100K = c(397, 575, 579, 591, 617, 733, 654, 690, 54, 79, 83, 88, 92, 76, 104, 107, 84, 89, 95, 101, 106, 123, 125, 133, 151, 249, 287, 249, 259, 245, 371, 378),
State = c("Florida", "Florida", "Florida", "Florida", "Florida", "Florida", "Florida", "Florida", "Massachusetts", "Massachusetts", "Massachusetts", "Massachusetts", "Massachusetts", "Massachusetts", "Massachusetts", "Massachusetts", "New York", "New York", "New York", "New York", "New York", "New York", "New York", "New York", "South Carolina", "South Carolina", "South Carolina", "South Carolina", "South Carolina", "South Carolina", "South Carolina", "South Carolina"),
stringsAsFactors = FALSE)
p <- mydf |> group_by(State) |> ec.init(ctype= 'line')
p$x$opts$series <- lapply(p$x$opts$series, function(ss) {
ss$endLabel <- list(show= TRUE, formatter= ec.clmn(3)); ss })
p$x$opts$tooltip <- list(show= TRUE)
p
@helgasoft

Copy link
Copy Markdown
Author

pictorialBar in timeline, inquiry by @rdatasculptor

df <- data.frame(x= c("a", "a"), score= c(10, 5), group= c(1, 2), sym= c("pin", "triangle"))

library(echarty)    # v.1.4.5.9001 and up
p <- df |> group_by(group) |> ec.init(
	tl.series= list(
		type= 'pictorialBar',
		encode= list(x= 'x', y= 'score'),
		symbol= ec.clmn(4),   # 4th column is symbol type
                symbolSize= 34, symbolRepeat=9)
)
p

image

@rdatasculptor

Copy link
Copy Markdown

@helgasoft this is very cool! Thank you for digging into this.

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