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
#'----------- echarty coding helper ------------ | |
#' Please report bugs and ask questions in https://github.com/helgasoft/echarty/issues | |
#' run in RStudio with command demo(coder), or demo(coder, package='echarty') | |
stopifnot('session non-interactive'= interactive()) | |
library(shiny) | |
library(shinyjs) | |
library(shinybusy) | |
library(dplyr) |
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
set.seed(22) | |
data <- tibble(x = 2 * pi * (1:100)/100) |> | |
mutate( | |
y1_bar = 0.5 * (sin(x)) + 1, | |
y2_bar = 0.5 * (sin(x)) - 1, | |
deltaY1 = rnorm(100, sd = 0.1), | |
deltaY2 = rnorm(100, sd = 0.1), | |
y1 = y1_bar + deltaY1, | |
y2 = y2_bar + deltaY2, | |
sizeY1 = abs(deltaY1), |
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, |
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
library(echarty) | |
url <- 'https://test.softpower.tw/echartstw/example/svg/football.svg' | |
svg <- url |> readLines(encoding='UTF-8') |> paste0(collapse="") | |
p <- ec.init(preset=FALSE, | |
backgroundColor= '#228b22', | |
geo= list("map"="football"), | |
title= list(text ='2014 World Cup', textStyle=list( color='#FFFF00'), | |
subtext='original JS code', subtextStyle= list(color='#FFFF00'), | |
sublink='https://test.softpower.tw/echartstw/example/map19.html' | |
), |
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
# Expanding on the great code from Milos Popovic | |
# new display as layer on Leaflet map, instead of ggplot | |
# original: https://github.com/milos-agathon/mapping-raster-files-with-terra-in-r | |
################################################################################ | |
# Mapping OSM and satelitte data with terra in R | |
# Milos Popovic | |
# 2022/09/22 | |
################################################################################ |
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
library(ggplot2) # for diamonds data =56K recs | |
library(dplyr) | |
data <- diamonds |> select(price, carat, cut) |> group_by(cut) | |
library(echarty) | |
p <- data |> | |
ec.init( # series & dataset are preset here | |
dataZoom= list(type='inside'), | |
tooltip= list(show= TRUE)) | |
p$x$opts$series <- lapply(p$x$opts$series, function(s) { |
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
#' inspired by https://juliasilge.com/blog/giant-pumpkins/ | |
#' advantage over ggplot is interactivity - zoom brush and tooltips | |
#' horizontal layout code at https://helgasoft.github.io/echarty/gallery.html#boxplot | |
library(tidyverse) | |
pumpkins_raw <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-19/pumpkins.csv") | |
pumpkins <- | |
pumpkins_raw |> | |
separate(id, into = c("year", "type")) |> | |
mutate(across(c(year, weight_lbs), parse_number)) |> |
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
library(dplyr) | |
library(lubridate) | |
# add event for clicking on blank area | |
jscode <- c('','',"chart.getZr().on('click', function(e) { | |
if (!e.target) alert('blank area: '+JSON.stringify(e.event)); });") | |
set.seed(421) | |
df1 <- tibble(date= as_date("2021-11-01") + months(0:11), | |
x= 12*10^6 + rnorm(12,0,2000000), | |
y= 12*10^6 + rnorm(12,0,1000000)) |
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
library(echarty) | |
radial_gradient <- htmlwidgets::JS( | |
"new echarts.graphic.RadialGradient(0.3, 0.3, 0.8)" | |
# ,[{ offset: 0, color: 'red'}, { offset: 1, color: 'red'}])" | |
) | |
color_stops <- htmlwidgets::JS( | |
"[{ offset: 0, color:'gold' }, // color at 0% | |
{ offset: 0.5, color:'MediumSlateBlue' }, // color at 50% | |
{ offset: 1, color:'skyblue' // color at 100% | |
}]" |
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
# (elegant) ggplot2 code to replicate in echarty | |
library(ggplot2) | |
iris |> | |
ggplot(aes(x = Species, y = Petal.Length)) + | |
geom_jitter(width = 0.1) | |
library(echarty); library(dplyr) | |
# with categorical axis |
NewerOlder