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
- Host: GitHub
- URL: https://github.com/dreamrs/uplot-r
- Owner: dreamRs
- License: other
- Created: 2022-07-27T16:06:25.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-29T16:11:15.000Z (6 months ago)
- Last Synced: 2025-06-12T13:46:28.478Z (5 months ago)
- Topics: data-visualization, htmlwidgets, r
- Language: JavaScript
- Homepage:
- Size: 9.96 MB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- License: LICENSE
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.
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](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"
)
```

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")
```

```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';}")
)
```
