• This repository has been archived on 12/Nov/2020
  • Stars
    star
    158
  • Rank 228,851 (Top 5 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 8 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

R ggplot2 "bindings" for Vega-Lite

vegalite : Do whatever ggvis doesn't :-)

For better examples, take a look here.

There's also a blog post describing this in a bit more detail.

The vegalite package has been updated to Vega-Lite 2.0, but is not yet 100% feature-complete.

In addition to functions for making a Vega-Lite based htmlwidget, functions also exist which enable creation of widgets from a JSON spec and turning a vegalite package created object into a JSON spec.

You start by calling vegalite() which allows you to setup core configuration options, including whether you want to display links to show the source and export the visualization. You can also set the background here and the viewport_width and viewport_height. Those are very important as they control the height and width of the widget and also the overall area for the chart. This does not set the height/width of the actual chart. That is done with view_size().

Once you instantiate the widget, you need to add_data() which can be data.frame, local CSV, TSV or JSON file (that convert to data.frames) or a non-realive URL (wich will not be read and converted but will remain a URL in the Vega-Lite spec.

You then need to encode_x() & encode_y() variables that map to columns in the data spec and choose one mark_...() to represent the encoding.

Here's a sample, basic Vega-Lite widget:

dat <- jsonlite::fromJSON('[
    {"a": "A","b": 28}, {"a": "B","b": 55}, {"a": "C","b": 43},
    {"a": "D","b": 91}, {"a": "E","b": 81}, {"a": "F","b": 53},
    {"a": "G","b": 19}, {"a": "H","b": 87}, {"a": "I","b": 52}
  ]')

vegalite() %>%
  add_data(dat) %>%
  encode_x("a", "ordinal") %>%
  encode_y("b", "quantitative") %>%
  mark_bar() -> vl

 vl

That is the minimum set of requirements for a basic Vega-Lite spec and will create a basic widget.

You can also convert that R widget object to_spec() which will return the JSON for the Vega-Lite spec (allowing you to use it outside of R).

to_spec(vl)

{
  "description": "",
  "data": {
    "values": [
      { "a": "A", "b": 28 }, { "a": "B", "b": 55 }, { "a": "C", "b": 43 },
      { "a": "D", "b": 91 }, { "a": "E", "b": 81 }, { "a": "F", "b": 53 },
      { "a": "G", "b": 19 }, { "a": "H", "b": 87 }, { "a": "I", "b": 52 }
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "a",
      "type": "nominal"
    },
    "y": {
      "field": "b",
      "type": "quantitative"
    }
  },
  "config": [],
  "embed": {
    "renderer": "svg",
    "actions": {
      "export": false,
      "source": false,
      "editor": false
    }
  }
}

If you already have a Vega-Lite JSON spec that has embedded data or a non-realtive URL, you can create a widget from it via from_spec() by passing in the full JSON spec or a URL to a full JSON spec.

If you're good with HTML (etc) and want a more lightweight embedding options, you can also use embed_spec which will scaffold a minimum div + script source and embed a spec from a vegalite object.

If you like the way Vega-Lite renders charts, you can also use them as static images in PDF knitted documents with the new capture_widget function. (NOTE that as of this writing, you can just use the development version of knitr instead of this function.)

Installation

devtools::install_github("hrbrmstr/vegalite")

Usage

library(vegalite)

# current verison
packageVersion("vegalite")
## [1] '2.0.0.9999'
library(vegalite)

vegalite() %>% 
  cell_size(400, 400) %>% 
  add_data("https://vega.github.io/vega-editor/app/data/cars.json") %>% 
  encode_x("Horsepower") %>% 
  encode_y("Miles_per_Gallon") %>% 
  encode_color("Origin", "nominal") %>% 
  mark_point()

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

More Repositories

1

hrbrthemes

πŸ” Opinionated, typographic-centric ggplot2 themes and theme components
R
1,139
star
2

pewpew

⭐ ⭐ ⭐ Build your own IP Attack Maps with SOUND!
JavaScript
990
star
3

waffle

🍁 Make waffle (square pie) charts in R
R
747
star
4

ggalt

🌎 Extra Coordinate Systems, Geoms, Statistical Transformations & Scales for 'ggplot2'
R
641
star
5

markdowntemplates

βœ…πŸ”» A collection of alternate R markdown templates
CSS
316
star
6

docxtractr

βœ‚οΈ Extract Tables from Microsoft Word Documents with R
R
169
star
7

ggchicklet

πŸ€« Create Chicklet (Rounded Segmented Column) Charts
HTML
157
star
8

streamgraph

〰️ htmlwidget for creating streamgraph visualizations in R
HTML
146
star
9

metricsgraphics

πŸ“ˆ htmlwidget interface to the MetricsGraphics.js D3 chart library
HTML
133
star
10

sergeant

πŸ’‚β€β™‚οΈ Tools to Transform and Query Data with 'Apache' 'Drill'
R
126
star
11

statebins

Alternative to choropleths of US States ala http://bit.ly/statebins
R
120
star
12

RSwitch

πŸŽ› A small menubar app that allows you to switch between R versions quickly (if you have multiple versions of R framework installed).
Swift
99
star
13

splashr

πŸ’¦ Tools to Work with the 'Splash' JavaScript Rendering Service in R
R
99
star
14

newsflash

Tools to Work with the Internet Archive and GDELT Television Explorer in R
R
88
star
15

curlconverter

➰ ➑️ βž– Translate cURL command lines into parameters for use with httr or actual httr calls (R)
R
88
star
16

darksky

☁️ R interface to the Dark Sky API [APPLE IS SHUTTING DOWN THE API 2022-12-31]
R
82
star
17

freebase

πŸ‘ƒπŸ½A 'usethis'-like Package for Base R Pseudo-equivalents of 'tidyverse' Code
R
82
star
18

albersusa

Tools, shapefiles & data to work with an "AlbersUSA" composite projection in R
R
75
star
19

21-recipes

πŸ“• An R/rtweet edition of Matthew A. Russell's Python Twitter Recipes Book
CSS
72
star
20

nominatim

🌏 Tools for Working with the 'Nominatim' API in R
R
71
star
21

hrbraddins

Additional Addins for RStudio
R
68
star
22

ggeconodist

πŸ“‰ Create Diminutive Distribution Charts
R
67
star
23

decapitated

Headless 'Chrome' Orchestration in R
R
66
star
24

taucharts

πŸ“Š An R htmlwidget interface to the TauCharts javascript library
HTML
65
star
25

speedtest

πŸ“ Measure upload/download speed/bandwidth for your network with R
R
64
star
26

ggcounty

🌐 Generate ggplot2 geom_map county maps
R
62
star
27

pluralize

An R package to "Pluralize and Singularize Any Word"
JavaScript
60
star
28

qrencoder

πŸ”³ Make QR codes in R via libqrencode
C
59
star
29

quarto-organization-template

A Quarto RevealJS Organization Boilerplate Template You Can Clone And Modify Quickly
SCSS
59
star
30

swatches

🎨 Read, Inspect, Manipulate, and Save (ASE-only for save) Color Swatch Files
R
56
star
31

cdcfluview

😷 R package to Retrieve U.S. Flu Season Data from the CDC FluView Portal (WHO & ILINet)
R
56
star
32

rgeocodio

Tools to Work with the https://geocod.io/ API
R
56
star
33

cloc

πŸ”’ R package to the perl cloc script (which counts blank lines, comment lines, and physical lines of source code in source files/trees/archives)
Perl
55
star
34

dtupdate

The dtupdate package has functions that try to make it easier to keep up with the non-CRAN universe
R
55
star
35

wayback

βͺ Tools to Work with the Various Internet Archive Wayback Machine APIs
R
54
star
36

orangetext

πŸŠπŸ“„ : An #rstats project to keep track of The 🍊 One's speeches
R
53
star
37

rstudioconf2017

Slides/code/data from rstudio:: conf 2017
ASP
52
star
38

ndjson

♨️ Wicked-Fast Streaming 'JSON' ('ndjson') Reader in R
C++
51
star
39

ggvis-maps

Examples of various kinds of maps in ggvis (with & without shiny)
R
51
star
40

iptools

🍴 A toolkit for manipulating, validating and testing IP addresses and ranges, along with datasets relating to IP addresses. While it primarily has support for the IPv4 address space, more extensive IPv6 support is intended.
Scilab
51
star
41

tidyweb

Easily Install and Load Modern Web-Scraping Packages
R
50
star
42

weatherkit

πŸŽπŸŒ‘πŸ”Ž Obtain Historical, Current, and Predictive Weather Data from Apple WeatherKit REST API in R
R
46
star
43

pdfbox

πŸ“„β—»οΈ Create, Maniuplate and Extract Data from PDF Files (R Apache PDFBox wrapper)
Java
46
star
44

xmlview

πŸ“ƒ Format, Query and Pretty Print 'HTML'/'XML' Content in R (RStudio viewer or browser)
JavaScript
46
star
45

msgxtractr

πŸ“‡ Extract contents from Outlook '.msg' files in R
C
44
star
46

worldtilegrid

πŸ”²πŸ—Ί World Tile Grid Geom for ggplot2 [WIP]
R
43
star
47

QuickLookR

macOS QuickLook plugin for R save(), saveRDS() & feather files
C
42
star
48

voteogram

U.S. House and Senate Voting Cartogram Generators in R
R
41
star
49

nifffty

Small R package to post events to IFTTT Maker channel/recipes
R
40
star
50

githubdashboard

#rstats github flexdashboard
HTML
40
star
51

overpass

ℹ️ Tools to Work With the OpenStreetMap (OSM) Overpass API in R
HTML
40
star
52

hrbragg

Typography-centric Themes, Theme Components, and Utilities for 'ggplot2' and 'ragg'.
R
39
star
53

netintel

A collection of "network intelligence" utilities for R. ASN info, IP reputation, etc.
R
39
star
54

htmlunit

πŸ•ΈπŸ§°β˜•οΈTools to Scrape Dynamic Web Content via the 'HtmlUnit' Java Library
R
38
star
55

Rforecastio

☁️ Simple R interface to forecast.io weather data
R
38
star
56

omdbapi

R package to access the OMDB API (http://www.omdbapi.com/)
R
38
star
57

mactheknife

🦈 Various β€˜macOS’-oriented Tools and Utilities in R
R
37
star
58

tdigest

Wicked Fast, Accurate Quantiles Using 't-Digests'
C
36
star
59

hrbrmisc

personal R pkg
R
35
star
60

webr-experiments

πŸ•ΈοΈ πŸ§ͺ hrbrmstr's WebR Experiments
HTML
34
star
61

2017-year-in-review

Year in Review with R Rmd Template
34
star
62

crafter

πŸ”¬ An R package to work with PCAPs
R
33
star
63

longurl

ℹ️ Small R package for no-API-required URL expansion
R
32
star
64

greywatch

πŸ•΅πŸ½ macOS Big Sur desktop app to monitor active TCP connections through the lens of GreyNoise
Swift
32
star
65

ipv4-heatmap

Update to The Measurement Factory ipv4-heatmap codebase
C
32
star
66

jsonview

JSON pretty printer & viewer in R
JavaScript
30
star
67

rpwnd

πŸ™… The Most Benignly Malicious R Package on the Internet
R
30
star
68

statically

πŸ“Έ Generate Webpage Screenshots Using the Statically API
R
28
star
69

rradar

🌊 Animate current U.S. NOAA NWS N0R Radar Images
R
27
star
70

archinfo

π–Ό† Returns a list of running processes and the architecture (x86_64/arm64) they are running under.
C
26
star
71

ohq2quarto

Save an Observable HQ Notebook to a Quarto project
Rust
25
star
72

osqueryr

⁇ 'osquery' 'DBI' and 'dbplyr' Interface for R
R
25
star
73

ulid

βš™οΈ Universally Unique Lexicographically Sortable Identifiers in R
C++
25
star
74

webr-monaco-repl

πŸ§ͺ πŸ•ΈοΈ Monaco-powered WebR "REPL"
JavaScript
24
star
75

imprint

Create Customized 'ggplot2' and 'R Markdown' Themes for Your Organization
R
24
star
76

gdns

Tools to work with the Google DNS over HTTPS API in R
R
24
star
77

2020-george-floyd-protests

Code to collect data from various sources on the 2020 George Floyd protests.
HTML
23
star
78

fileio

⏳ Ephemeral File, Text or R Data Sharing with 'file.io'
R
23
star
79

widgetcard

Tools to Enable Easier Content Embedding in Tweets
R
23
star
80

attckr

βš”οΈMITRE ATT&CK Machinations in R
R
23
star
81

mgrs

🌐 An R Package to Convert 'MGRS' (Military Grid Reference System) References From/To Other Coordiante Systems
C
23
star
82

webr-app

πŸ§ͺ πŸ•ΈοΈ A Way Better Structured WebR Demo App
JavaScript
23
star
83

xslt

lightweight XSLT processing package for R based on xmlwrapp
R
22
star
84

swiftr

Seamless R and Swift Integration
R
22
star
85

ggsolar

πŸͺ Generate "solar system" plots with {ggplot2}
R
22
star
86

facetedcountryheatmaps

Small sample Rmd to show how to make faceted country heatmaps in a couple different ways in R
HTML
22
star
87

firasans

πŸ” Fira Sans Condensed + Fira Mono Font Theme Based on hrbrthemes
R
22
star
88

pubcrawl

πŸΊπŸ“– Convert 'epub' Files to Text (Use https://github.com/ropensci/epubr instead)
R
22
star
89

ipapi

An R package to geolocate IPv4/6 addresses and/or domain names using ip-api.com's API
HTML
22
star
90

drill-sergeant-rstats

πŸ“— A Little Book About Using Apache Drill and R
R
22
star
91

slopegraph

A 'slopegraph' ('table-chart') generator in Python using Cairo/RaphaΓ«l. Currently handles a two column chart with _many_ output options. Look at the '/examples' directory for sample configurations, data files and output formats.
JavaScript
22
star
92

reveal-qmd

Chrome Extension To Reveal Observable Notebooks As Quarto QMD {ojs} Blocks & provide downloads of FileAttachments and zipped Quarto project
JavaScript
21
star
93

elpresidente

πŸ‡ΊπŸ‡Έ Search and Extract Corpus Elements from 'The American Presidency Project'
R
21
star
94

warc

πŸ“‡ Tools to Work with the Web Archive Ecosystem in R
R
21
star
95

wand

Use 'magic' to guess file types
R
21
star
96

rstudio-electron-quarto-installer

Download and install the latest macOS RStudio (electron) daily along with the latest Quarto pre-release
Shell
21
star
97

urlscan

πŸ‘€ Analyze Websites and Resources They Request
R
21
star
98

wondr

Tools to Work with there CDC WONDER API in R
R
20
star
99

supercaliheatmapwidget

πŸ“… Supercalifragilistic HTML Calendar Heatmaps
JavaScript
20
star
100

secede-2014

R dplyr/tidyr/rvest/TopoJSON tutorial using the 2014 Scotland secession vote
R
20
star