Git Product home page Git Product logo

vegalite's Introduction

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.

vegalite's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vegalite's Issues

Tooltip?

Any plan to add tooltip plugin support?

Vega-Lite 2.0 updates

Hi! Now that Vega-Lite 2.0 is out, can we update vegalite to add compatibility? The cross-filter interactions look super cool.

I've got a bit of time at the moment, so if there's a framework in which to assemble the pieces, I'm happy to help out.

vegalite doesn't render in the "Viewer" pane in RStudio when using remote files

This is perhaps an unusual item to report as an issue, but please bear with me.

vegalite often(**) fails to render anything in the "Viewer" pane in RStudio, it is completely blank - on Windows at least, with the problem seen on multiple different systems using different Windows OS versions, including my home PC, all using RStudio 1.0.136. (**it was "often" for me, until I identified the cause).

For example, the following (taken from the vegalite docn) renders nothing in RStudio. Interestingly, clicking the "Show In New Window" button in the "Viewer" pane opens the view in a new web browser window where the chart is rendered OK.

library(vegalite)
vegalite() %>%
cell_size(500, 300) %>%
add_data("https://vega.github.io/vega-editor/app/data/unemployment-across-industries.json") %>%
encode_x("date", "temporal") %>%
encode_y("count", "quantitative", aggregate="sum") %>%
encode_color("series", "nominal") %>%
scale_color_nominal(range="category20b") %>%
timeunit_x("yearmonth") %>%
scale_x_time(nice="month") %>%
axis_x(axisWidth=0, format="%Y", labelAngle=0) %>%
mark_area(interpolate="basis", stack="center")

Downloading the data file and changing the add_data() reference to the local copy of the file resolves the problem. This suggests quite strongly the problem is security permissions (likely in the embedded web browser control RStudio uses for the "Viewer" pane).

This is strictly speaking not an issue with vegalite but given the popularity of RStudio, I thought I'd report it here. A sensible way of dealing with this might be to add a few notes to the documentation to highlight the issue and the workarounds (i.e. click "Show In New Window" or avoid using remote files). This would avoid other people having similar frustration in RStudio with vegalite when the problem is not actually vegalite at all.

Problem passing ts to latest version of vegalite

Made a chart gallery, using Rmd and building with travis. My local vegalite version when used would render the charts fine (as would travis previously) but today with the latest install_github the charts are blank.

Page source indicates its generated some vega JS according to the source but it's whitespacing.

Code: https://github.com/stephlocke/chartgallery
Output: http://stephlocke.github.io/chartgallery/


Digging deeper I found that when I use a standalone example I get some interesting red text

if(!require(vegalite)) devtools::install_github("hrbrmstr/vegalite")
library(vegalite)
vegalite() %>%
  add_data(Seatbelts) %>%
  encode_x("PetrolPrice","quantitative") %>%
  encode_y("DriversKilled", "quantitative") %>%
  mark_point()

## Error in file.exists(source) : invalid 'file' argument
## In addition: Warning message:
## In if (is_url(source)) { :
##   the condition has length > 1 and only the first element will be used

Session info:

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] vegalite_0.5.1.9000

loaded via a namespace (and not attached):
[1] htmlwidgets_0.6 clipr_0.2.0     magrittr_1.5    htmltools_0.3   tools_3.2.3     jsonlite_0.9.19 digest_0.6.9  

R CMD check fails

fix this R CMD check ERROR: Running examples in
‘vegalite-Ex.R’ failed The error most likely
occurred in: > ### Name: from_spec > ### Title: Take
a JSON Vega-Lite Spec and render as an htmlwidget >
### Aliases: from_spec > > ### ** Examples > >
from_spec("http://rud.is/dl/embedded.json") Error in
file(con, "r") : cannot open the connection Calls:
from_spec -> readLines -> file Execution halted

This may be isolated to my local machine so I'd love to know if anyone can replicate this issue.

Update axes with new formal parameters

I'm working on getting some of the text settings that are now available in vegalite by adding them to the axes.R file based on this documentation: and plan to submit a PR.

However, I noticed that the axes.R file is very repetitive, since all axes get the same arguments and differ only on chnl.

Would @hrbrmstr be opposed to me refactoring the code so that there is a single axes function (could be internal or external) and that axes_* just calls that function with the chnl argument set? I would keep the documentation as is in all likelihood but it would make sure that adding new formal arguments from vegalite requires a lot less copy and paste work.

compile spec

What do you need to be able to translate a vegalite spec into ggplot2 commands? I see some V8 history. Is that what you need or do you need more? Happy to help.

widget "rendering" in PDF

via https://twitter.com/timelyportfolio/status/704527440853536772

i have an idea for this but it will require phantomjs being available.

Widgets require a working DOM & javascript environment. I haven't tried rendering any widgets to PDF but I can't imagine any of them working. But, we can send the widget to phantomjs, let it render there and then pull in the resulting bitmap.

I copied https://github.com/hrbrmstr/streamgraph/blob/master/R/phantom.R from another widget github issue discussion but can rejigger it to return markdown like ![](img.png) or proper HTML (or whatever wld be necessary for knitr).

thoughts, @timelyportfolio?

add multi-dataset?

Can we make different plots with different datasets and group them on the same canvas?
If not, is there a way to do it with your package?
Thanks

CRAN release planned for this week

For anyone tracking the project, it's actually good enough (IMO) for CRAN. If anyone does find any "gotchas" before end of week, pls drop an issue here. #ty

Included vegalite JS library not rendering titles correctly

Hello,
I produced a schema (see below) which when rendered in [https://vega.github.io/editor/] produced a steelblue title. However when I use vegalite in R, apart from title and anchor the other options are not respected( the title bit is at the bottom)

Is this because vegalite is using an older version of the JS library?



	  {
  "description": "",
  "data": {
    "values": [
      {
        "date": "2018-05-17",
        "dau": " 29.67 MM",
        "PctOn": "25.913877"
      },
      {
        "date": "2018-05-18",
        "dau": " 37.24 MM",
        "PctOn": "33.902391"
      },
      {
        "date": "2018-05-19",
        "dau": " 35.04 MM",
        "PctOn": "43.948684"
      },
      {
        "date": "2018-05-20",
        "dau": " 38.08 MM",
        "PctOn": "53.632520"
      },
      {
        "date": "2018-05-21",
        "dau": " 55.75 MM",
        "PctOn": "53.216210"
      },
      {
        "date": "2018-05-22",
        "dau": " 64.22 MM",
        "PctOn": "57.962003"
      },
      {
        "date": "2018-05-23",
        "dau": " 67.28 MM",
        "PctOn": "62.473247"
      },
      {
        "date": "2018-05-24",
        "dau": " 69.13 MM",
        "PctOn": "65.033222"
      },
      {
        "date": "2018-05-25",
        "dau": " 67.89 MM",
        "PctOn": "67.402715"
      },
      {
        "date": "2018-05-26",
        "dau": " 49.28 MM",
        "PctOn": "70.224833"
      },
      {
        "date": "2018-05-27",
        "dau": " 48.35 MM",
        "PctOn": "71.474268"
      },
      {
        "date": "2018-05-28",
        "dau": " 69.10 MM",
        "PctOn": "68.940195"
      },
      {
        "date": "2018-05-29",
        "dau": " 72.66 MM",
        "PctOn": "69.603291"
      },
      {
        "date": "2018-05-30",
        "dau": " 73.79 MM",
        "PctOn": "70.570328"
      },
      {
        "date": "2018-05-31",
        "dau": " 71.42 MM",
        "PctOn": "71.762926"
      },
      {
        "date": "2018-06-01",
        "dau": " 69.72 MM",
        "PctOn": "72.386425"
      },
      {
        "date": "2018-06-02",
        "dau": " 52.11 MM",
        "PctOn": "74.930149"
      },
      {
        "date": "2018-06-03",
        "dau": " 51.35 MM",
        "PctOn": "75.788678"
      },
      {
        "date": "2018-06-04",
        "dau": " 75.45 MM",
        "PctOn": "72.267049"
      },
      {
        "date": "2018-06-05",
        "dau": " 76.30 MM",
        "PctOn": "72.873080"
      },
      {
        "date": "2018-06-06",
        "dau": " 76.04 MM",
        "PctOn": "73.506603"
      },
      {
        "date": "2018-06-07",
        "dau": "102.98 MM",
        "PctOn": "78.148503"
      },
      {
        "date": "2018-06-08",
        "dau": " 85.08 MM",
        "PctOn": "76.292698"
      },
      {
        "date": "2018-06-09",
        "dau": " 58.95 MM",
        "PctOn": "77.844988"
      },
      {
        "date": "2018-06-10",
        "dau": " 55.66 MM",
        "PctOn": "78.892435"
      },
      {
        "date": "2018-06-11",
        "dau": " 80.09 MM",
        "PctOn": "75.640874"
      },
      {
        "date": "2018-06-12",
        "dau": " 79.10 MM",
        "PctOn": "75.694908"
      },
      {
        "date": "2018-06-13",
        "dau": " 78.93 MM",
        "PctOn": "75.673846"
      },
      {
        "date": "2018-06-14",
        "dau": " 76.87 MM",
        "PctOn": "75.801450"
      },
      {
        "date": "2018-06-15",
        "dau": " 70.86 MM",
        "PctOn": "76.380044"
      },
      {
        "date": "2018-06-16",
        "dau": " 51.44 MM",
        "PctOn": "79.324844"
      },
      {
        "date": "2018-06-17",
        "dau": " 52.05 MM",
        "PctOn": "80.192580"
      },
      {
        "date": "2018-06-18",
        "dau": " 77.34 MM",
        "PctOn": "76.921065"
      },
      {
        "date": "2018-06-19",
        "dau": " 77.77 MM",
        "PctOn": "76.500504"
      },
      {
        "date": "2018-06-20",
        "dau": " 76.73 MM",
        "PctOn": "76.698764"
      },
      {
        "date": "2018-06-21",
        "dau": " 76.60 MM",
        "PctOn": "76.738632"
      },
      {
        "date": "2018-06-22",
        "dau": " 72.63 MM",
        "PctOn": "77.297820"
      },
      {
        "date": "2018-06-23",
        "dau": " 53.88 MM",
        "PctOn": "79.685727"
      },
      {
        "date": "2018-06-24",
        "dau": " 52.59 MM",
        "PctOn": "80.643143"
      },
      {
        "date": "2018-06-25",
        "dau": " 79.21 MM",
        "PctOn": "77.450555"
      },
      {
        "date": "2018-06-26",
        "dau": " 79.17 MM",
        "PctOn": "75.230673"
      },
      {
        "date": "2018-06-27",
        "dau": " 72.08 MM",
        "PctOn": "67.394597"
      },
      {
        "date": "2018-06-28",
        "dau": " 64.31 MM",
        "PctOn": "62.763818"
      },
      {
        "date": "2018-06-29",
        "dau": " 58.21 MM",
        "PctOn": "58.219316"
      },
      {
        "date": "2018-06-30",
        "dau": " 37.96 MM",
        "PctOn": "52.978922"
      },
      {
        "date": "2018-07-01",
        "dau": " 32.61 MM",
        "PctOn": "48.178123"
      },
      {
        "date": "2018-07-02",
        "dau": " 44.96 MM",
        "PctOn": "43.791527"
      },
      {
        "date": "2018-07-03",
        "dau": " 39.52 MM",
        "PctOn": "38.465281"
      },
      {
        "date": "2018-07-04",
        "dau": " 33.12 MM",
        "PctOn": "34.018666"
      },
      {
        "date": "2018-07-05",
        "dau": " 30.19 MM",
        "PctOn": "30.651863"
      },
      {
        "date": "2018-07-06",
        "dau": " 25.58 MM",
        "PctOn": "24.091330"
      },
      {
        "date": "2018-07-07",
        "dau": " 17.06 MM",
        "PctOn": "22.994022"
      },
      {
        "date": "2018-07-08",
        "dau": " 15.69 MM",
        "PctOn": "23.419445"
      },
      {
        "date": "2018-07-09",
        "dau": " 22.69 MM",
        "PctOn": "21.995777"
      },
      {
        "date": "2018-07-10",
        "dau": " 20.79 MM",
        "PctOn": "20.105509"
      },
      {
        "date": "2018-07-11",
        "dau": " 17.21 MM",
        "PctOn": "16.791938"
      },
      {
        "date": "2018-07-12",
        "dau": " 13.36 MM",
        "PctOn": "13.507518"
      },
      {
        "date": "2018-07-13",
        "dau": " 10.65 MM",
        "PctOn": "11.555462"
      },
      {
        "date": "2018-07-14",
        "dau": "  7.49 MM",
        "PctOn": "11.462085"
      },
      {
        "date": "2018-07-15",
        "dau": "  6.85 MM",
        "PctOn": "11.006476"
      },
      {
        "date": "2018-07-16",
        "dau": "  9.54 MM",
        "PctOn": " 9.903564"
      },
      {
        "date": "2018-07-17",
        "dau": "  8.61 MM",
        "PctOn": " 8.806361"
      },
      {
        "date": "2018-07-18",
        "dau": "  7.75 MM",
        "PctOn": " 8.020007"
      },
      {
        "date": "2018-07-19",
        "dau": "  7.04 MM",
        "PctOn": " 7.439555"
      },
      {
        "date": "2018-07-20",
        "dau": "  6.19 MM",
        "PctOn": " 6.955740"
      },
      {
        "date": "2018-07-21",
        "dau": "  4.62 MM",
        "PctOn": " 7.131539"
      },
      {
        "date": "2018-07-22",
        "dau": "  4.43 MM",
        "PctOn": " 7.147067"
      },
      {
        "date": "2018-07-23",
        "dau": "  6.10 MM",
        "PctOn": " 6.477514"
      },
      {
        "date": "2018-07-24",
        "dau": "  5.66 MM",
        "PctOn": " 6.008673"
      },
      {
        "date": "2018-07-25",
        "dau": "  5.30 MM",
        "PctOn": " 5.676079"
      },
      {
        "date": "2018-07-26",
        "dau": "  4.97 MM",
        "PctOn": " 5.395066"
      },
      {
        "date": "2018-07-27",
        "dau": "  4.46 MM",
        "PctOn": " 5.117397"
      },
      {
        "date": "2018-07-28",
        "dau": "  3.37 MM",
        "PctOn": " 5.283396"
      },
      {
        "date": "2018-07-29",
        "dau": "  3.24 MM",
        "PctOn": " 5.311312"
      },
      {
        "date": "2018-07-30",
        "dau": "  4.67 MM",
        "PctOn": " 4.999567"
      },
      {
        "date": "2018-07-31",
        "dau": "  4.50 MM",
        "PctOn": " 4.759845"
      },
      {
        "date": "2018-08-01",
        "dau": "  4.29 MM",
        "PctOn": " 4.577594"
      },
      {
        "date": "2018-08-02",
        "dau": "  4.02 MM",
        "PctOn": " 4.353081"
      },
      {
        "date": "2018-08-03",
        "dau": "  3.69 MM",
        "PctOn": " 4.218323"
      },
      {
        "date": "2018-08-04",
        "dau": "  2.72 MM",
        "PctOn": " 4.295332"
      },
      {
        "date": "2018-08-05",
        "dau": "  2.61 MM",
        "PctOn": " 4.338866"
      },
      {
        "date": "2018-08-06",
        "dau": "  3.75 MM",
        "PctOn": " 4.095082"
      },
      {
        "date": "2018-08-07",
        "dau": "  3.59 MM",
        "PctOn": " 3.881396"
      },
      {
        "date": "2018-08-08",
        "dau": "  3.44 MM",
        "PctOn": " 3.696881"
      },
      {
        "date": "2018-08-09",
        "dau": "  3.29 MM",
        "PctOn": " 3.284490"
      },
      {
        "date": "2018-08-10",
        "dau": "  3.01 MM",
        "PctOn": " 2.908277"
      },
      {
        "date": "2018-08-11",
        "dau": "  2.21 MM",
        "PctOn": " 3.219112"
      },
      {
        "date": "2018-08-12",
        "dau": "  2.13 MM",
        "PctOn": " 3.342810"
      },
      {
        "date": "2018-08-13",
        "dau": "  3.08 MM",
        "PctOn": " 3.188096"
      }
    ]
  },
  "mark": "area",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "PctOn",
      "type": "quantitative"
    }
  },
  "transform": [],
  "title": {
    "text": "fish",
    "anchor": "start",
    "color": "steelblue",
    "fontSize": 5,
    "fontWeight": 100
  }
}

clash of vegalite versions using from_spec()

When I try one of the simple vegalite examples like:

from_spec('{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
          "description": "A simple bar chart with embedded data.",
          "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": "ordinal"},
          "y": {"field": "b", "type": "quantitative"}
          }
          }')

I correctly get the relevant plot.

With the following one, the cloropleth example with data files pointing to relevant URLs, nothing is displayed and no error is reported:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.1.json",
  "width": 500,
  "height": 300,
  "data": {
    "url": "https://raw.githubusercontent.com/vega/editor/master/data/us-10m.json",
    "format": {
      "type": "topojson",
      "feature": "counties"
    }
  },
  "transform": [
    {
      "lookup": "id",
      "from": {
        "data": {
          "url": "https://raw.githubusercontent.com/vega/editor/master/data/unemployment.tsv"
        },
        "key": "id",
        "fields": [
          "rate"
        ]
      }
    }
  ],
  "projection": {
    "type": "albersUsa"
  },
  "mark": "geoshape",
  "encoding": {
    "color": {
      "field": "rate",
      "type": "quantitative"
    }
  }
}

The above spec in Vega-lite Editor works flowlessly.

It looks like the issue is with vegalite version in the package with respect to the one defined in the spec, in the web console of the detached plot I get:

 The input spec uses vega-lite v2.1, but the current version of Vega-Lite is 2.0.1.

Namespace "%>%"

I guess it's more a remark than an issue, but if you use both dplyr and vegalite in a package, then there's a warning of R check because of "%>%" being exported from both packages. I used to do import vegalite, now I'm importing only all vegalite and each dplyr functions I need, except "%>%" that I only import from one package.

rmarkdown: vegalite + ggvis incompatability

vegalite does not play nicely with ggvis inside rmarkdown docs

In this gist, the rmarkdown errors, even though the ggvis chunk is not actively evaluated. However, if you flip it so vegalite is not eval'd & ggvis is eval'd, it works.

Tested on CRAN and dev version of rmarkdown, latest dev of vegalite, and cran ggvis

Rather a question than an issue

I wonder how to "print" several vegalite plots in a loop in RMarkdown? I tried using print() and results='asis' without success.

Versioning Number Changes

I'd like to make a proposal on versioning.

Vega-Lite 2.0 is currently in Alpha and will be released with support or Vega 3.0 and D3 v4.

The 1.0 milestone for vegalite in Rstats should represent what we believe is "feature complete for Vega-Lite 2.0. I would then recommend ratcheting to vegalite 2.0 milestone as meeting the Vega-Lite 2.0 spec. From there, I would recommend major versions being 0.X, minor 0.X.Y, and bug fixes as 0.X.Y.Z.

The first digit would reserved for the major version of Vega-Lite that this package targets.

I have created the 1.0 milestone as a starting point with the hope of tagging issues for the 1.0 release.

tooltips for line charts to show a tip for every point in a line

Hello,
I have code like

u=vegalite(title="FOO",viewport_width=320,viewport_height=260) %>%
  add_data(s)  %>%
  encode_x("date", "temporal") %>%
  encode_y("PctOn", "quantitative") %>%
  mark_line()

I'm using vegalite installed via devtools. When I hover over the line, the tool tip (really nice, thanks!) shows only the values from the last point in the series. The data set has 90 values, would it be possible to show the tooltip for every value?

Thanks much

background not exported?

If I do this

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(background="red", export=TRUE, renderer="canvas") %>%
    add_data(dat) %>%
    encode_x("a", "ordinal") %>%
    encode_y("b", "quantitative") %>%
    mark_bar()

and then export the image by clicking, the resulting PNG still has a transparent background, although the background was red in RStudio. Is this intended?

TODO: test harness

Most every function can be tested by creating "n" plots (i.e. find minimum set that includes all functions) , creating a spec from them and then comparing the generated spec to the "known good' one.

Namespace collisions

Several vegaltie functions now have collisions with either base R functions or popular packages like ggplot2 that may be simultaneously loaded.

Should we explicitly avoid these collisions? I half started a pattern of _vl with some of theee cases but I'm the not sure if that's the right approach.

Status of vegalite for R ?

Hello !

I wanted to do a quick check on the status of this effort here - I know this is a distinct effort from the altair package and this effort aims to build a native interface in R. But my question is do you think this package will keep pace with Vega-lite (it's currently at 4.17)?

I am trying to think about the pros and cons of a package that relies on reticulate and a python installation, vs. a native one such as this. To be clear, I am totally aware that maintaining a package such as this is an enormous effort and I'm not trying to demand anything, just trying to understand the intricacies of one approach vs. the other.

Timezone

When I use the code below, the second graph shows time as if it were in UTC, but I'd like to see the IST time. Do I need to change the timezone before plotting?

library("lubridate")
library("vegalite")
library("dplyr")

dateSeq <- seq(from = ymd_hms("2015-01-23 14:22:33"),
               length = 1000,
               by = "1 min")
data <- data.frame(date = dateSeq,
                   y = rnorm(n = 1000))
data %>% head()
tz(data$date)

vegalite() %>%
  cell_size(300, 300) %>%
  add_data(data) %>%
  encode_x("date", "temporal")  %>%
  timeunit_x("yearmonthdayhoursminutesseconds")%>%
  encode_y("y", "quantitative") %>%
  axis_x(ticks=20)%>%
  mark_tick()

data <- mutate(data,
               date = force_tz(dateSeq, tz = "Asia/Kolkata"))
data %>% head()
tz(data$date)

vegalite() %>%
  cell_size(300, 300) %>%
  add_data(data) %>%
  encode_x("date", "temporal")  %>%
  timeunit_x("yearmonthdayhoursminutesseconds")%>%
  encode_y("y", "quantitative") %>%
  axis_x(ticks=20)%>%
  mark_tick()

feature request: static_page function that creates html page from vl spec

Hi,

thanks for your library! I'd like to create dashboards with it that I host as static pages on s3. I was looking for a function that creates such a html file, but I couldn't find it.

The function embed_spec is described as follows:

Create minimal necessary HTML/JavaScript/CSS code to embed a Vega-Lite spec into a web page. This assumes you have the necessary boilerplate javascript & HTML page shell defined as you see in the Vega-Lite core example.

What about a function that doesn't create the scaffolding necessary to embed the spec, but creates a full static page? A static page that you can then share or upload to s3. Like the following function static_page

library(vegalite)

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}
  ]')

static_page <- function(vl_spec, file_path){
  output_string <-  paste(
    "<!DOCTYPE html>
    <html>
    <head>
    <title>Embedding Vega-Lite</title>
    <script src=\"https://cdn.jsdelivr.net/npm/vega@3\"></script>
      <script src=\"https://cdn.jsdelivr.net/npm/vega-lite@2\"></script>
        <script src=\"https://cdn.jsdelivr.net/npm/vega-embed@3\"></script>
          </head>
          <body>
          <div id=\"vis\"></div>
            
            <script type=\"text/javascript\">
              var yourVlSpec = ", 
    vl_spec, 
    ";
    vegaEmbed('#vis', yourVlSpec);
    </script>
      </body>
      </html>",
    sep = "") 
  
  write(output_string, file_path)
 }
       
vegalite() %>%
  add_data(dat) %>%
  encode_x("a", "ordinal") %>%
  encode_y("b", "quantitative") %>%
  mark_bar() %>% 
  to_spec() %>% 
  static_page(file_path =  "/tmp/vl.html")

I've taken the embedding code from https://vega.github.io/vega-lite/usage/embed.html#start-using-vega-lite-with-vega-embed

I think this would be a nice addition to the library. It definitely suits my use case.

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.