https://github.com/sciviews/chart
Unified interface to R charts
https://github.com/sciviews/chart
plot r r-package sciviews
Last synced: about 1 year ago
JSON representation
Unified interface to R charts
- Host: GitHub
- URL: https://github.com/sciviews/chart
- Owner: SciViews
- License: other
- Created: 2018-02-22T15:58:46.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-06-03T05:15:07.000Z (about 2 years ago)
- Last Synced: 2025-03-25T04:41:45.367Z (over 1 year ago)
- Topics: plot, r, r-package, sciviews
- Language: R
- Homepage: https://www.sciviews.org/chart
- Size: 4.44 MB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
title: "Unified Interface (with Formula) for R Plots
"
output: github_document
---
[](https://github.com/SciViews/chart/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/SciViews/chart?branch=main)
[](https://cran.r-project.org/package=chart)
[](https://sciviews.r-universe.dev/chart)
[](https://opensource.org/licenses/MIT)
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
```{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>",
fig.path = "man/figures/README-", out.width = "100%")
library(chart)
```
The {chart} package provides an alternate formula interface to {ggplot2}, and it also homogenize plot outputs from base R plots, {lattice} and {ggplot}. If labels and/or units attributes are defined for variables in the data, they are used automatically to construct the label (with units) of the axes. See for more details.
## Installation
{chart} is not available from CRAN yet. You should install it from the [SciViews R-Universe](https://sciviews.r-universe.dev). The {data.io} package is useful too because it manages labels and units that {chart} uses. To install those two packages and their dependencies, run the following command in R:
```{r, eval=FALSE}
install.packages(c('chart', 'data.io'),
repos = c('https://sciviews.r-universe.dev', 'https://cloud.r-project.org'))
```
You can also install the latest development version of {chart}. Make sure you have the {remotes} R package installed:
```{r, eval=FALSE}
install.packages("remotes")
```
Use `install_github()` to install the {chart} package from GitHub (source from **main** branch will be recompiled on your machine):
```{r, eval=FALSE}
remotes::install_github("SciViews/chart")
```
R should install all required dependencies automatically, and then it should compile and install {chart}.
## Further explore {chart}
Starting from the `airquality` from {datasets}, we can annotate our dataset with labels and units for its variable like this:
```{r}
data(airquality, package = "datasets")
airquality <- data.io::labelise(airquality, label = list(
Ozone = "Ozone", Temp = "Temperature", Solar.R = "Solar radiation",
Wind = "Wind speed"
), units = list(
Ozone = "ppb", Temp = "°F", Solar.R = "lang", Wind = "mph"
))
```
here is a first {chart}:
```{r}
library(chart)
chart(airquality, Ozone ~ Solar.R %col=% Temp) +
geom_point(na.rm = TRUE)
```
You will notice that the syntax is relatively close to {ggplot2}, except that `ggplot()` is here replaced by `chart()` and `aes(x = Solar.R, y = Ozone, col = Temp)` is replaced by a formula using `y ~ x` plus an optional series of `%%` terms where `` is the argument you would use in {ggplot2}'s `aes()` instruction (the `aes()` form is also accepted in `chart()`). The default style is also different and closer to a "publication-ready" version of the plot. Finally, labels and units we defined above in the `airquality` dataset are automatically used. Of course, you can override these labels with `labs()` if you want.
`chart()` is compatible with all {ggplot2} and ggplot2 extensions. It can also be used to create {lattice} or base R plots. Several specialized plots are available through `chart()` methods and types in separate packages, such as [{modelit}](https://www.sciviews.org/modelit/) and [{exploreit}](https://www.sciviews.org/exploreit/).
For further details, see . You can get further help about this package this way:
``` r
library(help = "chart")
help("chart-package")
vignette("chart") # Not installed with install_github()
```
## Code of Conduct
Please note that the {chart} package is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.