ec.util | R Documentation |
tabset, table layout, support for GIS shapefiles through library sf
ec.util(..., cmd = "sf.series", js = NULL)
... |
Optional parameters for the command |
cmd |
utility command, see Details |
js |
optional JavaScript function, default is NULL. |
cmd = 'sf.series'
Build leaflet or geo map series from shapefiles.
Supported types: POINT, MULTIPOINT, LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON
Coordinate system is leaflet(default) or geo
Limitations:
polygons can have only their name in tooltip,
assumes Geodetic CRS is WGS 84, use st_transform with crs=4326 to convert.
parameter df - value from st_read
optional parameters:
nid - column name for name-id used in tooltips
verbose - print shapefile item names in console
returns a list of chart series
cmd = 'sf.bbox'
returns JavaScript code to position a map inside a bounding box from st_bbox, for leaflet only.
cmd = 'sf.unzip'
unzips a remote file and returns local file name of the unzipped .shp file
url - URL of remote zipped shapefile
optional shp - name of .shp file inside ZIP file if multiple exist. Do not add file extension.
cmd = 'layout'
multiple charts in table-like rows/columns format
... - List of charts
optional parameters:
title - Title for the set, rows= Number of rows, cols= Number of columns,
width - Width of columns (one of xs, md, lg)
returns a container div in rmarkdown, otherwise browsable.
For 3-4 charts one would use multiple series within a grid.
For greater number of charts ec.util(cmd='layout') comes in handy
cmd = 'tabset'
... - a list tab-name/chart pairs like n1=chart1, n2=chart2
optional parameters are:
width - Width of tabs in pixels, height= Height of tabs in pixels
tabStyle - tab style string, see default tabStyle variable in the code
returns a tagList of tabs, each tab may contain a chart.
cmd = 'morph'
... - a list of charts or chart options
optional parameter:
js - JS function for switching charts. Default function is on mouseover.
returns a chart with ability to morph into other charts
cmd = 'fullscreen'
a toolbox feature to toggle fullscreen on/off. Works in a browser, not in RStudio.
cmd = 'rescale'
t - target range c(min,max), numeric vector of two
v - vector of numeric values to rescale
cmd = 'level'
calculate vertical levels for timeline line charts, returns a numeric vector
df - data.frame with from & to columns
from - name of 'from' column
to - name of 'to' column
cmd = 'labelsInside'
labelLayout function to keep overflowing endLabels inside chart
optional parameters:
cid - elementId of the chart when multiple charts
dy - vertical offset in pixels, negative up, positive down
if (interactive()) { # comm.out: Fedora errors about some 'browser' library(sf) fname <- system.file("shape/nc.shp", package="sf") nc <- as.data.frame(st_read(fname)) ec.init(load= c('leaflet', 'custom'), # load custom for polygons js= ec.util(cmd= 'sf.bbox', bbox= st_bbox(nc$geometry)), series= ec.util(df= nc, nid= 'NAME', itemStyle= list(opacity= 0.3)), tooltip= list(formatter= '{a}') ) htmltools::browsable( lapply(iris |> dplyr::group_by(Species) |> dplyr::group_split(), function(x) { x |> ec.init(ctype= 'scatter', title= list(text= unique(x$Species))) }) |> ec.util(cmd= 'tabset') ) p1 <- cars |> ec.init(grid= list(top= 20)) p2 <- mtcars |> ec.init() htmltools::browsable( ec.util(cmd= 'tabset', cars= p1, mtcars= p2, width= 200, height= 200) ) lapply(list('dark','macarons','gray','jazz','dark-mushroom'), function(x) cars |> ec.init() |> ec.theme(x) ) |> ec.util(cmd='layout', cols= 2, title= 'my layout') setd <- function(type) { mtcars |> group_by(cyl) |> ec.init(ctype=type) |> ec.upd({ title <- list(subtext='mouseover points to morph') xAxis <- list(scale=TRUE) series <- lapply(series, function(ss) { ss$groupId <- ss$name ss$universalTransition <- list(enabled=TRUE) ss }) }) } oscatter <- setd('scatter') obar <- setd('bar') ec.util(cmd='morph', oscatter, obar) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.