{"id":13426530,"url":"https://github.com/hrbrmstr/vegalite","last_synced_at":"2025-10-04T14:32:21.758Z","repository":{"id":56937704,"uuid":"52391615","full_name":"hrbrmstr/vegalite","owner":"hrbrmstr","description":"R ggplot2 \"bindings\" for Vega-Lite","archived":true,"fork":false,"pushed_at":"2018-07-30T17:44:43.000Z","size":14267,"stargazers_count":159,"open_issues_count":16,"forks_count":17,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-12-29T11:49:42.604Z","etag":null,"topics":["data-visualization","datavisualization","r","rstats","vega-lite","vega-lite-spec","visualization","widget"],"latest_commit_sha":null,"homepage":"http://rud.is/b/2016/02/27/create-vega-lite-specs-widgets-with-the-vegalite-package/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hrbrmstr.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-23T21:05:34.000Z","updated_at":"2024-09-16T01:47:11.000Z","dependencies_parsed_at":"2022-08-21T06:50:11.537Z","dependency_job_id":null,"html_url":"https://github.com/hrbrmstr/vegalite","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fvegalite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fvegalite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fvegalite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fvegalite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hrbrmstr","download_url":"https://codeload.github.com/hrbrmstr/vegalite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235264983,"owners_count":18962464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-visualization","datavisualization","r","rstats","vega-lite","vega-lite-spec","visualization","widget"],"created_at":"2024-07-31T00:01:37.134Z","updated_at":"2025-10-04T14:32:16.290Z","avatar_url":"https://github.com/hrbrmstr.png","language":"JavaScript","readme":"---\noutput:\n  html_document:\n    keep_md: true\n  md_document:\n    variant: markdown_github\n---\n![](gallery.png)\n\n`vegalite` : Do whatever `ggvis` doesn't :-)\n\nFor better examples, [take a look here](http://rud.is/projects/vegalite01.html).\n\nThere's also a [blog post](http://rud.is/b/2016/02/27/create-vega-lite-specs-widgets-with-the-vegalite-package/) describing this in a bit more detail.\n\nThe vegalite package has been updated to Vega-Lite 2.0, but is not yet 100% feature-complete.\n\nIn 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.\n\nYou 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()`.\n\nOnce you instantiate the widget, you need to `add_data()` which can be `data.frame`, local CSV, TSV or JSON file (that convert to `data.frame`s) or a non-realive URL (wich will not be read and converted but will remain a URL in the Vega-Lite spec.\n\nYou then need to `encode_x()` \u0026 `encode_y()` variables that map to columns in the data spec and choose one `mark_...()` to represent the encoding.\n\nHere's a sample, basic Vega-Lite widget:\n\n    dat \u003c- jsonlite::fromJSON('[\n        {\"a\": \"A\",\"b\": 28}, {\"a\": \"B\",\"b\": 55}, {\"a\": \"C\",\"b\": 43},\n        {\"a\": \"D\",\"b\": 91}, {\"a\": \"E\",\"b\": 81}, {\"a\": \"F\",\"b\": 53},\n        {\"a\": \"G\",\"b\": 19}, {\"a\": \"H\",\"b\": 87}, {\"a\": \"I\",\"b\": 52}\n      ]')\n\n    vegalite() %\u003e%\n      add_data(dat) %\u003e%\n      encode_x(\"a\", \"ordinal\") %\u003e%\n      encode_y(\"b\", \"quantitative\") %\u003e%\n      mark_bar() -\u003e vl\n\n     vl\n\nThat is the minimum set of requirements for a basic Vega-Lite spec and will create a basic widget.\n\nYou 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).\n\n    to_spec(vl)\n\n    {\n      \"description\": \"\",\n      \"data\": {\n        \"values\": [\n          { \"a\": \"A\", \"b\": 28 }, { \"a\": \"B\", \"b\": 55 }, { \"a\": \"C\", \"b\": 43 },\n          { \"a\": \"D\", \"b\": 91 }, { \"a\": \"E\", \"b\": 81 }, { \"a\": \"F\", \"b\": 53 },\n          { \"a\": \"G\", \"b\": 19 }, { \"a\": \"H\", \"b\": 87 }, { \"a\": \"I\", \"b\": 52 }\n        ]\n      },\n      \"mark\": \"bar\",\n      \"encoding\": {\n        \"x\": {\n          \"field\": \"a\",\n          \"type\": \"nominal\"\n        },\n        \"y\": {\n          \"field\": \"b\",\n          \"type\": \"quantitative\"\n        }\n      },\n      \"config\": [],\n      \"embed\": {\n        \"renderer\": \"svg\",\n        \"actions\": {\n          \"export\": false,\n          \"source\": false,\n          \"editor\": false\n        }\n      }\n    }\n\nIf 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.\n\nIf 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.\n\nIf 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.)\n\n### Installation\n\n```{r eval=FALSE}\ndevtools::install_github(\"hrbrmstr/vegalite\")\n```\n\n```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}\noptions(width=120, fig.retina=2)\n```\n\n### Usage\n\n```{r}\nlibrary(vegalite)\n\n# current verison\npackageVersion(\"vegalite\")\n\n```\n\n```{r eval=FALSE}\nlibrary(vegalite)\n\nvegalite() %\u003e% \n  cell_size(400, 400) %\u003e% \n  add_data(\"https://vega.github.io/vega-editor/app/data/cars.json\") %\u003e% \n  encode_x(\"Horsepower\") %\u003e% \n  encode_y(\"Miles_per_Gallon\") %\u003e% \n  encode_color(\"Origin\", \"nominal\") %\u003e% \n  mark_point()\n```\n\n![](vega.png)\n\n### Code of Conduct\n\nPlease note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.\n\n","funding_links":[],"categories":["JavaScript","Visualization"],"sub_categories":["General-Purpose"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fvegalite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhrbrmstr%2Fvegalite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fvegalite/lists"}