Skip to content

Instantly share code, notes, and snippets.

@helgasoft
helgasoft / map.tooltip.percent
Last active May 26, 2022 15:19
R | ECharts | map chart with tooltip percent formatter; map projection
cns <- countrycode::codelist$country.name.en
cns <- data.frame(
name = cns,
value = round(runif(length(cns), 1, 100), 2)
)
library(echarty)
p <- ec.init(load= 'world')
p$x$opts <- list(
series= list(list(
@helgasoft
helgasoft / eshiny.R
Last active July 22, 2021 23:21
Demo: echarty with Shiny
#'----------------- Interactive charts with echarty and Shiny -------------------
#' this code not maintained, see latest version in demo(eshiny, package='echarty')
library(shiny)
library(dplyr)
library(echarty)
base_df <- data.frame(ValX = c("A", "B", "C"), ValY = 1:3)
boxplot_df <- data.frame(ValX = sample(LETTERS[1:3], size = 20, replace = TRUE),
ValY = rnorm(20))
@helgasoft
helgasoft / echarty.sunburst.chart.R
Created May 30, 2021 16:48
echarty sunburst chart
#' data from https://github.com/tungmilan
#' see Hierarchies in https://helgasoft.github.io/echarty/uc3.html
DF <- data.frame(
parents = c("Mid Stream","Mid Stream","Mid Stream","Mid Stream",
"Mid Stream","Mid Stream","Mid Stream","Mid Stream",
"Mid Stream","Mid Stream","Mid Stream","Mid Stream",
"Low Stream","Low Stream",
"Low Stream","Low Stream",
"Low Stream","Mac River","Mac River","Mac River",
@helgasoft
helgasoft / shiny.chart.replace.R
Last active April 1, 2022 17:50
ECharts | R | chart replace in Shiny, events handling
#' replace chart series interactively in Shiny
#' idea from https://github.com/EKtheSage
library(shiny)
library(dplyr)
library(echarty)
ui <- fluidPage( titlePanel("echarty + Shiny"),
radioButtons('yvars',
label = 'Select a Y Variable to Plot',
selected = 'Sepal.Width',
@helgasoft
helgasoft / echarty-geo-map.R
Last active February 2, 2022 22:38
R | ECharts | timeline of geo map with scatter and lines; linked brush charts
library(echarty); library(dplyr)
flights <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv')
df <- head(flights) %>% relocate(start_lon, start_lat, end_lon) %>%
group_by(airport1) %>% group_split()
map.center <- c(mean(flights$start_lon), mean(flights$start_lat))
options <- lapply(df, function(y) {
series <- list(
list(type='scatter', coordinateSystem='geo',
data = ec.data(y, 'values'), symbolSize = 8),
@helgasoft
helgasoft / visualMap.R
Last active December 16, 2022 20:26
R | ECharts | heatmap and scatter with visualMap coloring
library(echarty)
library(dplyr)
# 1. --------------- ECharts heatmap with categorical data, like ggplot2::geom_tile
v <- LETTERS[1:10]
set.seed(2021)
matrix <- data.frame(
x = sample(v, 300, replace = TRUE),
y = sample(v, 300, replace = TRUE),
z = sample(LETTERS[1:3], 300, replace = TRUE),
@helgasoft
helgasoft / sankey.colors.R
Last active March 17, 2022 19:30
R | ECharts | sankey chart with node colors
sankey <- data.frame(
stringsAsFactors = TRUE,
source = c("Objetivo 1",
"Objetivo 2","Objetivo 3","Objetivo 4",
"Objetivo 1","Objetivo 2","Objetivo 3",
"Objetivo 4","Objetivo 1","Objetivo 2","Objetivo 3",
"Objetivo 4","Objetivo 1","Objetivo 2",
"Objetivo 3"),
target = c("ODS 17: Alianzas para lograr los objetivos",
"ODS 10: Reducción de las desigualdades",
@helgasoft
helgasoft / app.R
Last active April 18, 2023 18:25
Bathymetry demo with echarty
#' echarty demo for marmap
library(shiny)
library(shinydashboard)
library(shinybusy)
library(echarty)
library(marmap)
ui = dashboardPage(title='marmap', dashboardHeader(title='Bathymetry Demo'),
sidebar = dashboardSidebar(
fluidRow( column(12,
@helgasoft
helgasoft / app.R
Last active March 9, 2024 07:14
Echarty Translate Assistant - JavaScript data to R
library(shiny)
library(stringr)
library(echarty)
library(rclipboard) # for clipboard Copy button
library(formatR)
if (FALSE) { # notes
#' problem plot with Chinese chars:
#' text='<U+6F0F><U+6597><U+56FE>' > Sys.getlocale()
@helgasoft
helgasoft / echarty.scatterGL.R
Last active December 6, 2021 17:46
R | ECharts | Display big datasets with scatterGL and cartesian2d (GPU processing)
# ------ 1) prepare data
library(tibble)
dim <- 12500 # sample data half-quantity
slip <- if (dim %% 2) 0.1 else -0.1
setData <- function(offset) {
t <- tibble(x = runif(dim, max=10),
y = offset + sin(x) - x * slip * runif(dim))
round(t,3)
}