An open API service indexing awesome lists of open source software.

https://github.com/dreamrs/uplot-r

R htmlwidget for µPlot.js
https://github.com/dreamrs/uplot-r

data-visualization htmlwidgets r

Last synced: 3 months ago
JSON representation

R htmlwidget for µPlot.js

Awesome Lists containing this project

README

          

# uPlot

> R htmlwidget for [µPlot](https://github.com/leeoniya/uPlot) JavaScript library. μPlot is a fast, memory-efficient Canvas 2D-based chart for plotting time series, lines, areas, ohlc & bars.

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/dreamRs/uPlot-r/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dreamRs/uPlot-r/actions/workflows/R-CMD-check.yaml)

## Installation

You can install the development version of uPlot from [GitHub](https://github.com/dreamRs/uPlot-r) with:

```r
# install.packages("remotes")
remotes::install_github("dreamRs/uPlot-r")
```

## Example

Here's a time series in hourly steps over 12 years, representing a total of 874,584 points (9 series of 97,176).

```r
library(uPlot)
uPlot(data = eco2mix[, c(1, 3:11)]) %>%
uOptions(
title = "Electricity production by sources in France (2012 - 2023)"
) %>%
uColors(
"bioenergies" = "#156956",
"fuel" = "#80549f",
"coal" = "#a68832",
"solar" = "#d66b0d",
"gas" = "#f20809",
"wind" = "#72cbb7",
"hydraulic" = "#2672b0",
"nuclear" = "#e4a701",
"pumping" = "#0e4269"
)
```
![uPlot example](man/figures/uplot.png)

Area ranges examples :

```r
uPlot(data = temperatures) %>%
uOptions(
title = "Temperatures in 2022 with range from 2018 to 2021"
) %>%
uAxesY(
label = "Temperature in degree celsius",
values = JS("function(u, vals) {return vals.map(v => v + '°C');}")
) %>%
uBands("low", "high", fill = "#8485854D") %>%
uSeries("temperature", label = "Temperature (°C)", stroke = "red", width = 2) %>%
uSeries("low", label = "Low", stroke = "#848585", dash = c(8, 2)) %>%
uSeries("high", label = "High", stroke = "#848585", dash = c(8, 2)) %>%
uSeries("average", label = "Average", show = FALSE, stroke = "#111")
```

![temperature 1 example](man/figures/temperature1.png)

```r
uPlot(data = temperatures[, c(1, 2, 5)]) %>%
uOptions(
title = "Temperatures in 2022 compared to average from previous years"
) %>%
uAxesY(
label = "Temperature in degree celsius",
values = JS("function(u, vals) {return vals.map(v => v + '°C');}")
) %>%
uBands("temperature", "average", fill = "#F681804D") %>%
uBands("average", "temperature", fill = "#2F64FF4D") %>%
uSeries(
serie = "temperature",
label = "Temperature 2022",
stroke = "red",
width = 2,
value = JS("function(u, v) {return v === null ? '--' : uPlot.fmtNum(v) + '°C';}")
) %>%
uSeries(
serie = "average",
label = "Average 2018-2021",
stroke = "black",
width = 2,
value = JS("function(u, v) {return v === null ? '--' : uPlot.fmtNum(v) + '°C';}")
)
```

![temperature 2 example](man/figures/temperature2.png)