Movatterモバイル変換


[0]ホーム

URL:


CRAN statusR-CMD-checkR-CMD-check

altair

The goal of altair is to help you buildVega-Litevisualizations. This package usesreticulateto provide an interface to theAltair Pythonpackage, and thevegawidgetpackage to render charts as htmlwidgets. To avoid confusion, thecapitalized wordAltair shall refer to the Pythonpackage; the lower-case wordaltair shall refer to thisR package.

This version of the R package supports Python Altair version4.2.0.

Example

This example is discussed in detail in ourGettingStarted article:

library("altair")vega_data<-import_vega_data()chart<-  alt$Chart(vega_data$cars())$mark_point()$encode(x ="Horsepower:Q",y ="Miles_per_Gallon:Q",color ="Origin:N"  )chart

Some things to keep in mind:

These and other “gotchas” are compiled along with workarounds in anarticle:FieldGuide to Python Issues.

Installation

You can install altair from CRAN with:

install.packages("altair")

The development version of is available fromGitHub:

# install.packages("devtools")devtools::install_github("vegawidget/altair")

Because of Python, there may be some additional installation steps,described in greater detail in theInstallationarticle.

  1. Python must be installed on your system. We have had successusingConda: in particular,Minicondaworks well and installs more-quickly than Anaconda.

    If you work in a corporate or institutional environment, you may haveto specify the location of your SSL certificate, or deal with a proxy.The installation article has asectionon this.

  2. Create a Conda environment called"r-reticulate".The reticulate folksrecommendstandardizing on a common name for all packages that use reticulate. Formore information, there is asectionin the installation article.

  3. Install Altair into your"r-reticulate" environmentusingaltair::install_altair().

  4. Important: (Python) Altair 4.2.0 does note workwith Pandas 2.0; use Pandas 1.5.3 (for example). This is fixed for(Python) Altair 5, which will be made available in an upcoming releaseof (R) altair.

You may wish to add a line like this to the.First()function in your.Rprofile:

reticulate::use_condaenv("r-reticulate")

Theuse_condaenv() function is called to provide ahintto reticulate on which Python environment to use.

Optional installations

If you have theV8 installed,you can usevegawidget’simage-generating functions to convert Altair charts into SVG stringsor write SVG files. With thersvg andpng packagesinstalled, you can get a bitmap array, or write PNG files.

When knitting to a non-HTML format,e.g. github_document, this package provides aknit_print() function that will intercept the normalrenderer, using instead its own renderer, allowing you to specify"png" ,"svg" or"pdf". Like theimage functions, this requires that the V8 package be installed, as wellasrsvg andpng. MacOS users willrequire an X11 system, such asXQuartz, to be installed.

Articles

The documentation for this package includes somearticles:

Gallery:

Examples:

Field Guides:

Acknowledgements

This package rests on these foundations:

As well, a particular debt is owed to the folks behind thevegalite package, as itprovided a lot of the inspiration for these efforts.

This project is a collaborative effort. In addition to the principalauthors:

Contributing

Please note that this project is released with aContributorCode of Conduct. By participating in this project you agree to abideby its terms.

This project also has aContributingGuide.


[8]ページ先頭

©2009-2025 Movatter.jp