library("readr")
library("tibble")
library("lubridate")
library("magrittr")
library("vegawidget")

Categorical data

set.seed(314159)
n_cat <- 10

data_category <- 
  tibble(
    category = letters[seq(n_cat)],
    number = as.integer(runif(n_cat) * 100)
  ) %>%
  glimpse()

Daily data

This data is taken from the vega-datasets repository. For this dataset, the source is NOAA.

data_seattle_daily <- 
  read_csv("https://vega.github.io/vega-datasets/data/seattle-weather.csv")

Hourly data

data_seattle_hourly <- 
  read_csv("https://vega.github.io/vega-datasets/data/seattle-weather-hourly-normals.csv") %>%
  glimpse()

# need to correct one of the times (this instant does not exist in local time)
data_seattle_hourly$date[data_seattle_hourly$date == "2010-03-14T02:00:00"] <-
  "2010-03-14T03:00:00"

data_seattle_hourly$date <- 
  parse_date_time(
    data_seattle_hourly$date, 
    orders = "%Y/%m/%d %H:%M:%S",
    tz = "America/Los_Angeles"
  )  

data_seattle_hourly$temp <- data_seattle_hourly$temperature

data_seattle_hourly <- data_seattle_hourly[, c("date", "temp")]
glimpse(data_seattle_hourly)

mtcars

The data are documented in R/data.R.

spec_mtcars <-
  as_vegaspec(
    list(
      `$schema` = "https://vega.github.io/schema/vega-lite/v5.json",
      width = 300L,
      height = 300L,
      description = "An mtcars example.",
      data = list(values = mtcars),
      mark = "point",
      encoding = list(
        x = list(field = "wt", type = "quantitative"),
        y = list(field = "mpg", type = "quantitative"),
        color = list(field = "cyl", type = "nominal")
      )
    )     
  )

class(spec_mtcars)

Write it out

usethis::use_data(
  data_category,
  data_seattle_daily,
  data_seattle_hourly,
  spec_mtcars,
  overwrite = TRUE  
)


vegawidget/vegawidget documentation built on Jan. 27, 2024, 10:48 a.m.