Last active
July 17, 2024 20:33
-
-
Save helgasoft/e914fe6f4a9ed9407f78e41cb18b3aaa to your computer and use it in GitHub Desktop.
echarty announcements and temporary notes
This file contains 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
#' 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)) | |
) |
@antoine4ucsd, please open an issue in echarty with a working code example
sure. thank you
dplyr::arrange is typically used for reordering
df <- data.frame(
name = c("yes", "no", "yes", "no", "yes", "yes",'dn','dn','dn','dn'),
value = c(5, 3, 4, 2, 6, 1, 8,4,2,1)
) |> dplyr::summarise(n= dplyr::n(), .by= name) |>
dplyr::mutate(
N = sum(n),
pct = round(n / N, 2),
lab_pct = str_c(round(pct * 100), "%"),
lab_n = str_c(n, " / ", N)
)
library(echarty)
df |>
dplyr::select(name,n) |> dplyr::arrange(n,name) |> # reordering
ec.init(ctype='bar'
,grid= list(containLabel=TRUE)
,xAxis= list(name=' ',
axisLabel= list(rotate= 66), scale=TRUE,
axisTick= list(alignWithLabel= TRUE))
,yAxis= list(name='count', nameLocation='center', nameRotate=90, nameGap=20)
,barWidth= 3, barGap= '-100%'
) |>
ec.upd({
scat <- lapply(series, function(bar) {
within(bar, { # set matching scatter serie
type <- 'scatter'
encode <- list(x='name', y='n')
label <- list(show=TRUE, formatter= '{@n}')
symbolSize <- 25
itemStyle <- list(opacity= 1, borderWidth=2, borderColor= 'cornsilk')
})
})
series <- append(series, scat)
}) # |> ec.theme('inspired')
Yes, my bad. it works fine now. thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
may I ask one more question...
creating a lollipop chart,
it works just fine apart from the fact that the order of the data in the x axis does not match my factor
can't find how to properly reorder...sorry about that.