| Version: | 4.2.3 |
| Title: | Interface to 'Altair' |
| Description: | Interface to 'Altair'https://altair-viz.github.io, which itself is a 'Python' interface to 'Vega-Lite'https://vega.github.io/vega-lite/. This package uses the 'Reticulate' frameworkhttps://rstudio.github.io/reticulate/ to manage the interface between R and 'Python'. |
| SystemRequirements: | Python (>= 3.6.0), (Python) Altair (>= 4.2.0),vega_datasets (>= 0.9.0). To use image functions for MacOS: X11 |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| ByteCompile: | true |
| URL: | https://github.com/vegawidget/altair |
| BugReports: | https://github.com/vegawidget/altair/issues |
| Imports: | reticulate (≥ 1.23), htmlwidgets, assertthat, magrittr,utils, vegawidget (≥ 0.4.1), repr |
| Suggests: | httr, rprojroot, purrr, readr, knitr, rmarkdown, tibble,listviewer (≥ 2.0.0), testthat, pryr, stringr, tidyr, dplyr,pkgdown, V8, rsvg, png, fs |
| RoxygenNote: | 7.2.3 |
| NeedsCompilation: | no |
| Packaged: | 2023-09-04 01:22:53 UTC; ijlyttle |
| Author: | Ian Lyttle |
| Maintainer: | Ian Lyttle <ijlyttle@me.com> |
| Repository: | CRAN |
| Date/Publication: | 2023-09-04 03:50:02 UTC |
altair: Create and embed Vega-Lite charts using the Altair Python package
Description
The goal of altair is to help you buildVega-Lite visualizations. Using thereticulate package, it providesan interface to theAltair Python package.
Details
In this documentation, the capitalized wordAltair shall refer to thePython package; the lower-case wordaltair shall refer to this R package.
Author(s)
Maintainer: Ian Lyttleijlyttle@me.com (ORCID)
Authors:
Haley Jeppsonhjeppson@iastate.edu
Altair Developers
Other contributors:
Alicia Schepaschep@gmail.com (ORCID) [contributor]
Jake Vanderplas (Altair library) [contributor]
Brian Granger (Altair library) [contributor]
See Also
altair pkgdown website,Altair Python package,Vega-Lite
Pipe operator
Description
Seemagrittr::%>% for details.
Usage
lhs %>% rhsMark character strings as literal JavaScript code
Description
This function is re-exported from the htmlwidgets package.Seehtmlwidgets::JS() for more details.
Usage
JS(...)See Also
Altair object
Description
Uses the reticulate framework to access the Altair API.
Usage
altFormat
An object of classpython.builtin.module (inherits frompython.builtin.object) of length 1.
Details
The Altair Python package is exposed through thealt object.You can create and add to chart using its methods and classes,as outlined in theAltair Python documentation.
In this package, use the$ operator wherever you see the. operatorused in Python.
See Also
Altair Python documentation,altair: Field Guide to Python Issues
Examples
if (interactive()) { vega_data <- import_vega_data() plot_basic <- alt$Chart(vega_data$cars())$ encode( x = "Miles_per_Gallon:Q", y = "Horsepower:Q", color = "Origin:N" )$ mark_point() plot_basic}Altair plot concatenation
Description
Altair plots can be concatenated using the following operators:+,|, and&
Usage
## S3 method for class 'altair.vegalite.v4.api.TopLevelMixin'e1 | e2## S3 method for class 'altair.vegalite.v4.api.TopLevelMixin'e1 + e2## S3 method for class 'altair.vegalite.v4.api.TopLevelMixin'e1 & e2Arguments
e1 | Altair chart object |
e2 | Altair chart object |
Value
Compound Altair chart object
Examples
if (interactive()){ # Examples using the beaver1 and beaver2 body temperature data sets # Layering Charts base <- alt$Chart(beaver1)$encode( x = alt$X('time'), y = alt$Y('temp', scale = alt$Scale(zero = FALSE)) ) scatter_plot <- base$mark_point() line_plot <- base$mark_line() combined_plot <- scatter_plot + line_plot # Horizontal Concatenation base2 <- alt$Chart(beaver2)$ encode( x = alt$X("time"), y = alt$Y("temp", scale = alt$Scale(zero = FALSE)) ) scatter_plot2 <- base2$mark_point() line_plot2 <- base2$mark_line() combined_plot <- (scatter_plot + line_plot)$ properties(title = "Beaver 1", width = 200) combined_plot2 <- (scatter_plot2 + line_plot2)$ properties(title = "Beaver 2", width = 200) hconcat_plot <- combined_plot | combined_plot2 # Vertical Concatenation vconcat_plot <- combined_plot & combined_plot2}Installed versions of Altair, Vega, etc.
Description
Returns a named list of version tags for Altair, Vega, Vega-Lite,and Vega-Embed
Usage
altair_version()Value
namedlist of version tags
Examples
if (interactive()) { altair_version()}Create Altair chart from vegaspec
Description
Create Altair chart from vegaspec
Usage
as_chart(spec)Arguments
spec | An object to be coerced to |
Value
altair object
Examples
if (interactive()) { as_chart(vegawidget::spec_mtcars) }Coerce to vegaspec
Description
Seevegawidget::as_vegaspec for details.
Usage
## S3 method for class 'altair.vegalite.v4.api.TopLevelMixin'as_vegaspec(spec, ...)Arguments
spec | An object to be coerced to |
... | Other arguments (attempt to future-proof) |
Check the Altair installation
Description
Provides feedback on any differences between your installedversion of Altair and the version this package supports.
Usage
check_altair(quiet = FALSE)Arguments
quiet |
|
Details
If the supported Altair version is different from your installedversion, this function will act according to where thedifference in the version numbers:
major version leads to anerror
minor version leads to awarning
patch version leads to amessage
If there is no difference:
quiet = FALSE, success message showing version-numbersquiet = TRUE, no message
To install the supported version into a Python environmentcalled"r-reticulate", useinstall_altair().
Value
invisibleNULL, called for side-effects
See Also
reticulate::py_config(),install_altair(),altair_version()
Examples
## Not run: # not run because it requires Python check_altair()## End(Not run)Create or write image
Description
Seevegawidget::image for details.
Import Vega datasets
Description
Lets you access Vega datasets.
Usage
import_vega_data()Details
Returns thedata object in the Python packagevega-datasets.In the documentation for this package, the convention is toassign this object to the namevega_data.
Value
An S3 object of classvega_datasets.core.DataLoader
See Also
Examples
if (interactive()) { vega_data <- import_vega_data() # To list available datasets print(vega_data$list_datasets()) # When accessing a dataset, substitute any "-" in the name with a "_" print(head(vega_data$sf_temps())) # Metadata are available for each dataset: print(vega_data$anscombe$references) print(vega_data$anscombe$description) print(vega_data$anscombe$url) # For local datasets, local path is available print(vega_data$sf_temps$filepath)}Install Altair Python package
Description
This function wraps installation functions fromreticulate to install the Python packagesaltair andvega_datasets.
Usage
install_altair( method = c("conda", "virtualenv"), envname = "r-reticulate", version = getOption("altair.python.version"), ...)Arguments
method |
|
envname |
|
version |
|
... | other arguments sent to |
Details
This package uses thereticulate packageto make an interface with theAltairPython package. To promote consistency in usage ofreticulate amongdifferent R packages, it isrecommendedto use a common Python environment, called"r-reticulate".
Depending on your setup, you can create this environment usingreticulate::conda_create() orreticulate::virtualenv_create(),as described in thisreticulate article,or in this package'sInstallation article.
Value
invisibleNULL, called for side-effects
See Also
altiar: Installation,reticulate: Using reticulate in an R Package,reticulate: Installing Python Packages
Examples
## Not run: # not run because it requires Python install_altair()## End(Not run)Knit-print method
Description
Seevegawidget::knit_print.vegaspec for details,particularly on additional packages that may have to be installed.
Usage
knit_print.altair.vegalite.v4.api.TopLevelMixin(spec, ..., options = NULL)Arguments
spec | An object to be coerced to |
... | other arguments |
options |
|
Render shiny-output for vegawidget
Description
Deprecated, please usevegawidget::renderVegawidget.
Usage
renderVegawidget(expr, env = parent.frame(), quoted = FALSE)Arguments
expr | expression that generates a vegawidget. This can bea |
env | The environment in which to evaluate |
quoted | Is |
MIME method for text
Description
MIME method for text
Usage
## S3 method for class 'altair.vegalite.v4.api.TopLevelMixin'repr_text(obj, ...)Arguments
obj | Altair chart object to be rendered |
Value
character
MIME method for chart rendering
Description
MIME method for chart rendering
Usage
## S3 method for class 'altair.vegalite.v4.api.TopLevelMixin'repr_vegalite4(obj, ...)Arguments
obj | Altair chart object to be rendered |
Value
list, reflecting JSON spec
Vega embed options
Description
Seevegawidget::vega_embed for details.
Create a Vega/Vega-Lite htmlwidget
Description
Seevegawidget::vegawidget for details.
Shiny-output for vegawidget
Description
Deprecated, please usevegawidget::vegawidgetOutput.
Usage
vegawidgetOutput(outputId, width = "auto", height = "auto")Arguments
outputId | output variable to read from |
width,height | Must be a valid CSS unit (like |
Coerce vegaspec to JSON
Description
Deprecated, please usevegawidget::vw_as_json.
Usage
vw_as_json(spec, pretty = TRUE)Arguments
spec | An object to be coerced to |
pretty |
|
Value
jsonlite::json object
Set base URL
Description
Seevegawidget::vw_set_base_url for details.