Title: | A Vector Spatio-Temporal Data Structure for Data Analysis |
---|---|
Description: | A spatiotemperal data object in a relational data structure to separate the recording of time variant/ invariant variables. See the Journal of Statistical Software reference: <doi:10.18637/jss.v110.i07>. |
Authors: | H. Sherry Zhang [aut, cre] , Dianne Cook [aut] , Ursula Laa [aut] , Nicolas Langrené [aut] , Patricia Menéndez [aut] |
Maintainer: | H. Sherry Zhang <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-11-04 05:51:11 UTC |
Source: | https://github.com/huizezhang-sherry/cubble |
Accessors to a cubble object
## S3 method for class 'spatial_cubble_df' data[i, j, drop = FALSE] ## S3 method for class 'temporal_cubble_df' data[i, j, drop = FALSE] ## S3 replacement method for class 'spatial_cubble_df' names(x) <- value ## S3 replacement method for class 'temporal_cubble_df' names(x) <- value ## S3 replacement method for class 'cubble_df' x[[i]] <- value
## S3 method for class 'spatial_cubble_df' data[i, j, drop = FALSE] ## S3 method for class 'temporal_cubble_df' data[i, j, drop = FALSE] ## S3 replacement method for class 'spatial_cubble_df' names(x) <- value ## S3 replacement method for class 'temporal_cubble_df' names(x) <- value ## S3 replacement method for class 'cubble_df' x[[i]] <- value
data |
an object of class |
i , j
|
row and column selector |
drop |
logical. If |
x |
data frame. |
value |
a suitable replacement value: it will be repeated a whole
number of times if necessary and it may be coerced: see the
Coercion section. If |
For nested cubbles, [
will return a cubble object if the key
variable, thecoords
variables, and the ts
column all present.
If the cubble object is also an sf object, the sticky select behavior on
the sf column will preserve. For long cubbles, [
will return a cubble
object if the key
and index
variable both present.
When a cubble can't be created and the data is not an sf class,
[
will always return a tibble, even with single index selection.
climate_mel[c(1:3, 7)] # a nested cubble make_spatial_sf(climate_mel)[1:3] # an sf long <- climate_mel |> face_temporal() long[1:3] # a long cubble climate_mel[1:3] # tibble long[2:5] # tibble climate_mel[1] # still tibble long[1] # and still tibble
climate_mel[c(1:3, 7)] # a nested cubble make_spatial_sf(climate_mel)[1:3] # an sf long <- climate_mel |> face_temporal() long[1:3] # a long cubble climate_mel[1:3] # tibble long[2:5] # tibble climate_mel[1] # still tibble long[1] # and still tibble
dplyr
methodsVerbs supported for both nested and long cubble include:
dplyr::mutate()
, dplyr::filter()
, dplyr::arrange()
, dplyr::select()
,
dplyr::group_by()
, dplyr::ungroup()
, dplyr::summarise()
,.
dplyr::rename()
, dplyr::bind_cols()
, dplyr::rowwise()
,
dplyr::slice_*()
, dplyr::*_join()
, dplyr::relocate()
,
dplyr::pull()
## S3 method for class 'temporal_cubble_df' arrange(.data, ...) ## S3 method for class 'spatial_cubble_df' select(.data, ...) ## S3 method for class 'temporal_cubble_df' select(.data, ...) ## S3 method for class 'spatial_cubble_df' group_by(.data, ..., .add, .drop) ## S3 method for class 'temporal_cubble_df' group_by(.data, ..., .add, .drop) ## S3 method for class 'spatial_cubble_df' ungroup(x, ...) ## S3 method for class 'temporal_cubble_df' ungroup(x, ...) ## S3 method for class 'spatial_cubble_df' summarise(.data, ..., .by = NULL, .groups = NULL) ## S3 method for class 'temporal_cubble_df' summarise(.data, ..., .by = key_vars(.data), .groups = NULL) ## S3 method for class 'spatial_cubble_df' rename(.data, ...) ## S3 method for class 'temporal_cubble_df' rename(.data, ...) bind_rows.temporal_cubble_df(..., .id = NULL) bind_cols.spatial_cubble_df(..., .name_repair) bind_cols.temporal_cubble_df(..., .name_repair) ## S3 method for class 'spatial_cubble_df' rowwise(data, ...) ## S3 method for class 'temporal_cubble_df' rowwise(data, ...) ## S3 method for class 'cubble_df' dplyr_col_modify(data, cols) ## S3 method for class 'spatial_cubble_df' dplyr_row_slice(data, i, ...) ## S3 method for class 'temporal_cubble_df' dplyr_row_slice(data, i, ...) ## S3 method for class 'spatial_cubble_df' dplyr_reconstruct(data, template) ## S3 method for class 'temporal_cubble_df' dplyr_reconstruct(data, template) ## S3 method for class 'spatial_cubble_df' mutate(.data, ...) ## S3 method for class 'temporal_cubble_df' mutate(.data, ...) ## S3 method for class 'spatial_cubble_df' filter(.data, ...) ## S3 method for class 'spatial_cubble_df' arrange(.data, ...)
## S3 method for class 'temporal_cubble_df' arrange(.data, ...) ## S3 method for class 'spatial_cubble_df' select(.data, ...) ## S3 method for class 'temporal_cubble_df' select(.data, ...) ## S3 method for class 'spatial_cubble_df' group_by(.data, ..., .add, .drop) ## S3 method for class 'temporal_cubble_df' group_by(.data, ..., .add, .drop) ## S3 method for class 'spatial_cubble_df' ungroup(x, ...) ## S3 method for class 'temporal_cubble_df' ungroup(x, ...) ## S3 method for class 'spatial_cubble_df' summarise(.data, ..., .by = NULL, .groups = NULL) ## S3 method for class 'temporal_cubble_df' summarise(.data, ..., .by = key_vars(.data), .groups = NULL) ## S3 method for class 'spatial_cubble_df' rename(.data, ...) ## S3 method for class 'temporal_cubble_df' rename(.data, ...) bind_rows.temporal_cubble_df(..., .id = NULL) bind_cols.spatial_cubble_df(..., .name_repair) bind_cols.temporal_cubble_df(..., .name_repair) ## S3 method for class 'spatial_cubble_df' rowwise(data, ...) ## S3 method for class 'temporal_cubble_df' rowwise(data, ...) ## S3 method for class 'cubble_df' dplyr_col_modify(data, cols) ## S3 method for class 'spatial_cubble_df' dplyr_row_slice(data, i, ...) ## S3 method for class 'temporal_cubble_df' dplyr_row_slice(data, i, ...) ## S3 method for class 'spatial_cubble_df' dplyr_reconstruct(data, template) ## S3 method for class 'temporal_cubble_df' dplyr_reconstruct(data, template) ## S3 method for class 'spatial_cubble_df' mutate(.data, ...) ## S3 method for class 'temporal_cubble_df' mutate(.data, ...) ## S3 method for class 'spatial_cubble_df' filter(.data, ...) ## S3 method for class 'spatial_cubble_df' arrange(.data, ...)
... |
In |
.add |
When This argument was previously called |
.drop |
Drop groups formed by factor levels that don't appear in the
data? The default is |
x |
A |
.by |
< |
.groups |
Grouping structure of the result.
When
In addition, a message informs you of that choice, unless the result is ungrouped,
the option "dplyr.summarise.inform" is set to |
.id |
The name of an optional identifier column. Provide a string to create an output column that identifies each input. The column will use names if available, otherwise it will use positions. |
.name_repair |
One of |
data , .data
|
a cubble object of class |
cols |
A named list used to modify columns. A |
i |
A numeric or logical vector that indexes the rows of |
template |
Template data frame to use for restoring attributes. |
You may find not all the verbs have a verb.spatial_cubble_df
or
verb.temporal_cubble_df
implemented. These verbs call
the dplyr extending trios: dplyr_row_slice
, dplyr_col_modify
,
and dplyr_reconstruct
under the hood.
See https://dplyr.tidyverse.org/reference/dplyr_extending.html
library(dplyr) cb_nested <- climate_mel cb_long <- face_temporal(climate_mel) # filter - currently filter.spatial_cubble_df, dply_row_slice cb_nested |> filter(elev > 40) cb_long |> filter(prcp > 0) # mutate - curerntly mutate.spatial_cubble_df, dply_col_modify cb_nested |> mutate(elev2 = elev + 10) cb_long |> mutate(prcp2 = prcp + 10) # arrange - currently arrange.spatial_cubble_df, arrange.temporal_cubble_df cb_nested |> arrange(wmo_id) cb_long |> arrange(prcp) # summarise - summarise.spatial_cubble_df, summarise.temporal_cubble_df cb_long |> group_by(first_5 = ifelse(lubridate::day(date) <=5, 1, 2 )) |> summarise(tmax = mean(tmax)) cb_long |> mutate(first_5 = ifelse(lubridate::day(date) <=5, 1, 2)) |> summarise(t = mean(tmax), .by = first_5) # select - select.spatial_cubble_df, select.temporal_cubble_df cb_nested |> select(name) cb_nested |> select(-id, -name) cb_long |> select(prcp) cb_long |> select(-prcp, -date) # rename - rename.spatial_cubble_df, rename.temporal_cubble_df cb_nested |> rename(elev2 = elev) cb_long |> rename(prcp2 = prcp) # rename on key attributes cb_nested |> rename(id2 = id) cb_long |> rename(date2 = date) # join - mutate_join - dplyr_reconstruct() # join - filter_join - dplyr_row_slice() df1 <- cb_nested |> as_tibble() |> select(id, name) |> head(2) nested <- cb_nested |> select(-name) nested |> left_join(df1, by = "id") nested |> right_join(df1, by = "id") nested |> inner_join(df1, by = "id") nested |> full_join(df1, by = "id") nested |> anti_join(df1, by = "id") # bind_rows - dplyr_reconstruct, bind_rows.temporal_cubble_df df1 <- cb_nested |> head(1) df2 <- cb_nested |> tail(2) bind_rows(df1, df2) df1 <- cb_long |> head(10) df2 <- cb_long |> tail(20) bind_rows(df1, df2) # relocate - dplyr_col_select, dplyr_col_select cb_nested |> relocate(ts, .before = name) cb_nested |> face_temporal() |> relocate(tmin) # slice - all the slice_* uses dplyr::slice(), which uses dplyr_row_slice() cb_nested |> slice_head(n = 2) cb_nested |> slice_tail(n = 2) cb_nested |> slice_max(elev) cb_nested |> slice_min(elev) cb_nested |> slice_sample(n = 2) # rowwise - rowwise.spatial_cubble_df, rowwise.temporal_cuble_df cb_nested |> rowwise() cb_long |> rowwise() # group_by & ungroup - (res <- cb_nested |> mutate(group1 = c(1, 1, 2)) |> group_by(group1)) res |> ungroup() (res2 <- res |> face_temporal()) res2 |> ungroup() res2 |> mutate(first_5 = ifelse(lubridate::day(date) <= 5, 1, 6)) |> group_by(first_5)
library(dplyr) cb_nested <- climate_mel cb_long <- face_temporal(climate_mel) # filter - currently filter.spatial_cubble_df, dply_row_slice cb_nested |> filter(elev > 40) cb_long |> filter(prcp > 0) # mutate - curerntly mutate.spatial_cubble_df, dply_col_modify cb_nested |> mutate(elev2 = elev + 10) cb_long |> mutate(prcp2 = prcp + 10) # arrange - currently arrange.spatial_cubble_df, arrange.temporal_cubble_df cb_nested |> arrange(wmo_id) cb_long |> arrange(prcp) # summarise - summarise.spatial_cubble_df, summarise.temporal_cubble_df cb_long |> group_by(first_5 = ifelse(lubridate::day(date) <=5, 1, 2 )) |> summarise(tmax = mean(tmax)) cb_long |> mutate(first_5 = ifelse(lubridate::day(date) <=5, 1, 2)) |> summarise(t = mean(tmax), .by = first_5) # select - select.spatial_cubble_df, select.temporal_cubble_df cb_nested |> select(name) cb_nested |> select(-id, -name) cb_long |> select(prcp) cb_long |> select(-prcp, -date) # rename - rename.spatial_cubble_df, rename.temporal_cubble_df cb_nested |> rename(elev2 = elev) cb_long |> rename(prcp2 = prcp) # rename on key attributes cb_nested |> rename(id2 = id) cb_long |> rename(date2 = date) # join - mutate_join - dplyr_reconstruct() # join - filter_join - dplyr_row_slice() df1 <- cb_nested |> as_tibble() |> select(id, name) |> head(2) nested <- cb_nested |> select(-name) nested |> left_join(df1, by = "id") nested |> right_join(df1, by = "id") nested |> inner_join(df1, by = "id") nested |> full_join(df1, by = "id") nested |> anti_join(df1, by = "id") # bind_rows - dplyr_reconstruct, bind_rows.temporal_cubble_df df1 <- cb_nested |> head(1) df2 <- cb_nested |> tail(2) bind_rows(df1, df2) df1 <- cb_long |> head(10) df2 <- cb_long |> tail(20) bind_rows(df1, df2) # relocate - dplyr_col_select, dplyr_col_select cb_nested |> relocate(ts, .before = name) cb_nested |> face_temporal() |> relocate(tmin) # slice - all the slice_* uses dplyr::slice(), which uses dplyr_row_slice() cb_nested |> slice_head(n = 2) cb_nested |> slice_tail(n = 2) cb_nested |> slice_max(elev) cb_nested |> slice_min(elev) cb_nested |> slice_sample(n = 2) # rowwise - rowwise.spatial_cubble_df, rowwise.temporal_cuble_df cb_nested |> rowwise() cb_long |> rowwise() # group_by & ungroup - (res <- cb_nested |> mutate(group1 = c(1, 1, 2)) |> group_by(group1)) res |> ungroup() (res2 <- res |> face_temporal()) res2 |> ungroup() res2 |> mutate(first_5 = ifelse(lubridate::day(date) <= 5, 1, 6)) |> group_by(first_5)
Coerce foreign objects into a cubble object
as_cubble(data, key, index, coords, ...) ## S3 method for class 'data.frame' as_cubble(data, key, index, coords, ...) ## S3 method for class 'tbl_df' as_cubble(data, key, index, coords, crs, dimensions, ...) ## S3 method for class 'sf' as_cubble(data, key, index, ...) ## S3 method for class 'ncdf4' as_cubble( data, key, index, coords, vars, lat_range = NULL, long_range = NULL, ... ) ## S3 method for class 'stars' as_cubble(data, key, index, coords, ...) ## S3 method for class 'sftime' as_cubble(data, key, index, coords, ...)
as_cubble(data, key, index, coords, ...) ## S3 method for class 'data.frame' as_cubble(data, key, index, coords, ...) ## S3 method for class 'tbl_df' as_cubble(data, key, index, coords, crs, dimensions, ...) ## S3 method for class 'sf' as_cubble(data, key, index, ...) ## S3 method for class 'ncdf4' as_cubble( data, key, index, coords, vars, lat_range = NULL, long_range = NULL, ... ) ## S3 method for class 'stars' as_cubble(data, key, index, coords, ...) ## S3 method for class 'sftime' as_cubble(data, key, index, coords, ...)
data |
an object to be converted into an cubble object. Currently
support objects of classes |
key |
a character (symbol), the spatial identifier,
see |
index |
a character (symbol), the temporal identifier,
see |
coords |
a vector of character (symbol) of length 2,
see |
... |
other arguments. |
crs |
used in |
dimensions |
used when creating a cubble from a stars object |
vars |
a vector of variables to read in (with quote),
used in |
lat_range , long_range
|
in the syntax of |
a cubble object
climate_flat |> as_cubble(key = id, index = date, coords = c(long, lat)) # only need `coords` if create from a tsibble dt <- climate_flat |> tsibble::as_tsibble(key = id, index = date) dt |> as_cubble(coords = c(long, lat)) # netcdf path <- system.file("ncdf/era5-pressure.nc", package = "cubble") raw <- ncdf4::nc_open(path) dt <- as_cubble(raw) # subset degree dt <- as_cubble(raw,vars = c("q", "z"), long_range = seq(113, 153, 3), lat_range = seq(-53, -12, 3)) ## Not run: # stars - take a few seconds to run tif <- system.file("tif/L7_ETMs.tif", package = "stars") x <- stars::read_stars(tif) x |> as_cubble(index = band) ## End(Not run) # don't have to supply coords if create from a sftime dt <- climate_flat |> sf::st_as_sf(coords = c("long", "lat"), crs = sf::st_crs("OGC:CRS84")) |> sftime::st_as_sftime() dt |> as_cubble(key = id, index = date)
climate_flat |> as_cubble(key = id, index = date, coords = c(long, lat)) # only need `coords` if create from a tsibble dt <- climate_flat |> tsibble::as_tsibble(key = id, index = date) dt |> as_cubble(coords = c(long, lat)) # netcdf path <- system.file("ncdf/era5-pressure.nc", package = "cubble") raw <- ncdf4::nc_open(path) dt <- as_cubble(raw) # subset degree dt <- as_cubble(raw,vars = c("q", "z"), long_range = seq(113, 153, 3), lat_range = seq(-53, -12, 3)) ## Not run: # stars - take a few seconds to run tif <- system.file("tif/L7_ETMs.tif", package = "stars") x <- stars::read_stars(tif) x |> as_cubble(index = band) ## End(Not run) # don't have to supply coords if create from a sftime dt <- climate_flat |> sf::st_as_sf(coords = c("long", "lat"), crs = sf::st_crs("OGC:CRS84")) |> sftime::st_as_sftime() dt |> as_cubble(key = id, index = date)
When creating a cubble from separate spatial and temporal component,
make_cubble()
will informed users about potential disagreement
of the key values in the two datasets (some sites appear in one table
but not the other). This function summarises the key values into those
match, potentially can be matched, and can't be matched.
check_key(spatial, temporal, by = NULL)
check_key(spatial, temporal, by = NULL)
spatial |
a tibble object or an sf object, the spatial component
containing the |
temporal |
a tibble object or a tsibble object, the temporal component
containing the |
by |
in the syntax of the |
a list with three elements: 1) paired: a tibble of paired ID from spatial and temporal data, 2) potential_pairs: a tibble of pairs that could potentially match from both datasets, 3) others: other key values that can't be matched in a list: others$temporal and others$spatial
check_key(stations, meteo) # make_cubble() will prompt to use check_key if there are key mis-match: colnames(lga) <- c("lga", "geometry") cb <- make_cubble(spatial = lga, temporal = covid) (check_res <- check_key(lga, covid)) make_cubble(spatial = lga, temporal = covid, potential_match = check_res)
check_key(stations, meteo) # make_cubble() will prompt to use check_key if there are key mis-match: colnames(lga) <- c("lga", "geometry") cb <- make_cubble(spatial = lga, temporal = covid) (check_res <- check_key(lga, covid)) make_cubble(spatial = lga, temporal = covid, potential_match = check_res)
climate_aus
: daily measure on precipitation (prcp
),
maximum temperature (tmax
), and minimum temperature (tmin
)
in 2020 for 639 stations. historical_tmax
: daily maximum temperature
(tmax
) for 75 stations in Victoria and New South Wales for two
periods: 1971-1975 and 2016-2020.
climate_aus historical_tmax
climate_aus historical_tmax
An object of class spatial_cubble_df
(inherits from cubble_df
, tbl_df
, tbl
, data.frame
) with 639 rows and 7 columns.
An object of class spatial_cubble_df
(inherits from cubble_df
, tbl_df
, tbl
, data.frame
) with 75 rows and 7 columns.
station ID, "ASN000" are international paddings, the next two digits (digit 8-9) indicates the states the station is in: Western Australia: 01-13, Northern Territory: 14-15, South Australia: 16-26, Queensland: 27-45, New South Wales: 46-75, Victoria: 76-90, Tasmania: 91-99. See http://www.bom.gov.au/climate/cdo/about/site-num.shtml
latitude of the stations, in degree
longitude of the stations, in degree
elevation of the stations
station name
the world meteorological organisation (WMO) station number
For climate_aus
: date, prcp, tmax, and tmin, for
historical_tmax
: date and tmax
climate_aus |> face_temporal() |> face_spatial()
climate_aus |> face_temporal() |> face_spatial()
tsibble
) and Victoria LGA (in sf
)Daily COVID count data (covid
) from 2022-01-01 to 2020-03-23 in a
tsibble object (date
, lga
, n
, and avg_7day
).
Victoria Local Government Area (LGA) spatial geometry in an sf object
(lga_name_2018
and geometry
)
covid lga
covid lga
An object of class tbl_ts
(inherits from tbl_df
, tbl
, data.frame
) with 6806 rows and 4 columns.
An object of class sf
(inherits from data.frame
) with 80 rows and 2 columns.
date object, from 2022-01-01 to 2020-03-23
Victoria Local Government Area (LGA) in Australia
COVID-19 case count
rolling mean of n
in a 7 day window.
Calculate with mutate(avg_7day = slider::slide_dbl(n,
mean, .before = 6))
LGA encoding by Australia Bureau of Statistics,
slightly differ from the encoding used by the Department of Health
in the covid
data
multipolygon geometry of each LGA
library(sf) library(dplyr) # prompt msg on the key mismatch between the two datasets make_cubble(lga, covid, by = c("lga_name_2018" = "lga")) check_res <- check_key(lga, covid, by = c("lga_name_2018" = "lga")) # fix mismatch lga2 <- lga |> rename(lga = lga_name_2018) |> mutate(lga = ifelse(lga == "Kingston (C) (Vic.)", "Kingston (C)", lga), lga = ifelse(lga == "Latrobe (C) (Vic.)", "Latrobe (C)", lga)) |> filter(!lga %in% check_res$others$spatial) covid2 <- covid |> filter(!lga %in% check_res$others$temporal) make_cubble(spatial = lga2, temporal = covid2)
library(sf) library(dplyr) # prompt msg on the key mismatch between the two datasets make_cubble(lga, covid, by = c("lga_name_2018" = "lga")) check_res <- check_key(lga, covid, by = c("lga_name_2018" = "lga")) # fix mismatch lga2 <- lga |> rename(lga = lga_name_2018) |> mutate(lga = ifelse(lga == "Kingston (C) (Vic.)", "Kingston (C)", lga), lga = ifelse(lga == "Latrobe (C) (Vic.)", "Latrobe (C)", lga)) |> filter(!lga %in% check_res$others$spatial) covid2 <- covid |> filter(!lga %in% check_res$others$temporal) make_cubble(spatial = lga2, temporal = covid2)
Create a cubble object
cubble(..., key, index, coords) make_cubble( spatial, temporal, by = NULL, key, index, coords, potential_match = NULL, key_use = "temporal" )
cubble(..., key, index, coords) make_cubble( spatial, temporal, by = NULL, key, index, coords, potential_match = NULL, key_use = "temporal" )
... |
a set of name-value pairs to create a cubble, need to include the
|
key |
a character (or symbol), the spatial identifier. See the Key
section in |
index |
a character (or symbol), the temporal identifier.
Currently support base R classes |
coords |
a vector of character (or symbol) of length two, in the order of longitude first and then latitude, the argument can be omitted if created from an sf and its subclasses. In case the sf geometry column is not POINT, coords will be the centroid coordinates. |
spatial |
a tibble object or an sf object, the spatial component
containing the |
temporal |
a tibble object or a tsibble object, the temporal component
containing the |
by |
in the syntax of the |
potential_match |
a |
key_use |
a character of either "spatial" or "temporal". When
|
a cubble object
cubble( id = rep(c("perth", "melbourne", "sydney"), each = 3), date = rep(as.Date("2020-01-01") + 0:2, times = 3), long = rep(c(115.86, 144.96, 151.21), each = 3), lat = rep(c(-31.95, -37.81, -33.87), each = 3), value = rnorm(n = 9), key = id, index = date, coords = c(long, lat) ) # stations and climate are in-built data in cubble make_cubble(spatial = stations, temporal = meteo, key = id, index = date, coords = c(long, lat))
cubble( id = rep(c("perth", "melbourne", "sydney"), each = 3), date = rep(as.Date("2020-01-01") + 0:2, times = 3), long = rep(c(115.86, 144.96, 151.21), each = 3), lat = rep(c(-31.95, -37.81, -33.87), each = 3), value = rnorm(n = 9), key = id, index = date, coords = c(long, lat) ) # stations and climate are in-built data in cubble make_cubble(spatial = stations, temporal = meteo, key = id, index = date, coords = c(long, lat))
While face_temporal()
switches a cubble object into a long cubble,
suitable for temporal operations, face_spatial()
turns a long cubble back
into a nest cubble for spatial operations. The two operations are exact
inverse.
face_temporal(data, col) ## S3 method for class 'temporal_cubble_df' face_temporal(data, col) ## S3 method for class 'spatial_cubble_df' face_temporal(data, col) face_spatial(data) ## S3 method for class 'spatial_cubble_df' face_spatial(data) ## S3 method for class 'temporal_cubble_df' face_spatial(data)
face_temporal(data, col) ## S3 method for class 'temporal_cubble_df' face_temporal(data, col) ## S3 method for class 'spatial_cubble_df' face_temporal(data, col) face_spatial(data) ## S3 method for class 'spatial_cubble_df' face_spatial(data) ## S3 method for class 'temporal_cubble_df' face_spatial(data)
data |
a cubble object |
col |
a character (or a symbol), the list column to be expanded,
|
a cubble object
cubble: An R Package for Organizing and Wrangling Multivariate Spatio-Temporal Data
cb_long <- climate_mel |> face_temporal() cb_back <- cb_long |> face_spatial() identical(climate_mel, cb_back)
cb_long <- climate_mel |> face_temporal() cb_back <- cb_long |> face_spatial() identical(climate_mel, cb_back)
Gap-filling on the temporal component of a cubble object
## S3 method for class 'temporal_cubble_df' fill_gaps(.data, ..., .full = FALSE, .start = NULL, .end = NULL) ## S3 method for class 'temporal_cubble_df' scan_gaps(.data, ...) ## S3 method for class 'temporal_cubble_df' index_by(.data, ...)
## S3 method for class 'temporal_cubble_df' fill_gaps(.data, ..., .full = FALSE, .start = NULL, .end = NULL) ## S3 method for class 'temporal_cubble_df' scan_gaps(.data, ...) ## S3 method for class 'temporal_cubble_df' index_by(.data, ...)
.data |
A tsibble. |
... |
A set of name-value pairs. The values provided will only replace
missing values that were marked as "implicit", and will leave previously
existing
|
.full |
|
.start , .end
|
Set custom starting/ending time that allows to expand the existing time spans. |
a cubble object
library(tsibble) climate_aus |> face_temporal() |> fill_gaps() climate_aus |> face_temporal() |> scan_gaps()
library(tsibble) climate_aus |> face_temporal() |> fill_gaps() climate_aus |> face_temporal() |> scan_gaps()
Create glyph map with ggplot2
geom_glyph( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., x_major = NULL, x_minor = NULL, y_major = NULL, y_minor = NULL, x_scale = identity, y_scale = identity, polar = FALSE, width = ggplot2::rel(2.1), height = ggplot2::rel(1.8), global_rescale = TRUE, show.legend = NA, inherit.aes = TRUE ) geom_glyph_line( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., x_major = NULL, x_minor = NULL, y_major = NULL, y_minor = NULL, polar = FALSE, width = ggplot2::rel(2.1), height = ggplot2::rel(2.1), show.legend = NA, inherit.aes = TRUE ) geom_glyph_box( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., x_major = NULL, x_minor = NULL, y_major = NULL, y_minor = NULL, polar = FALSE, width = ggplot2::rel(2.1), height = ggplot2::rel(2.1), show.legend = NA, inherit.aes = TRUE )
geom_glyph( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., x_major = NULL, x_minor = NULL, y_major = NULL, y_minor = NULL, x_scale = identity, y_scale = identity, polar = FALSE, width = ggplot2::rel(2.1), height = ggplot2::rel(1.8), global_rescale = TRUE, show.legend = NA, inherit.aes = TRUE ) geom_glyph_line( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., x_major = NULL, x_minor = NULL, y_major = NULL, y_minor = NULL, polar = FALSE, width = ggplot2::rel(2.1), height = ggplot2::rel(2.1), show.legend = NA, inherit.aes = TRUE ) geom_glyph_box( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., x_major = NULL, x_minor = NULL, y_major = NULL, y_minor = NULL, polar = FALSE, width = ggplot2::rel(2.1), height = ggplot2::rel(2.1), show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
x_major , x_minor , y_major , y_minor
|
The name of the variable (as a
string) for the major and minor x and y axes. Together, each unique
combination of |
y_scale , x_scale
|
The scaling function to be applied to each set of
minor values within a grid cell. Defaults to |
polar |
A logical of length 1, specifying whether the glyphs should
be drawn in polar coordinates. Defaults to |
height , width
|
The height and width of each glyph. Defaults to 95% of
the |
global_rescale |
Whether rescale is performed globally or on each individual glyph. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
a ggplot object
print_p <- GGally::print_if_interactive library(ggplot2) # basic glyph map with reference line and box--------------- p <- ggplot(data = GGally::nasa, aes(x_major = long, x_minor = day, y_major = lat, y_minor = surftemp)) + geom_glyph_box() + geom_glyph_line() + geom_glyph() + theme_bw() print_p(p) # rescale on each individual glyph --------------- p <- ggplot(data = GGally::nasa, aes(x_major = long, x_minor = day, y_major = lat, y_minor = surftemp)) + geom_glyph(global_rescale = FALSE) print_p(p) # adjust width and height with relative & absolute value --------------- p <- ggplot() + geom_glyph(data = GGally::nasa, aes(x_major = long, x_minor = day, y_major = lat, y_minor = surftemp), width = rel(0.8), height = 1) + theme_bw() print_p(p) # apply a re-scaling on Y and use polar coordinate p <- GGally::nasa |> ggplot(aes(x_major = long, x_minor = day, y_major = lat, y_minor = ozone)) + geom_glyph_box(fill=NA) + geom_glyph_line() + geom_glyph(y_scale = GGally::range01, polar = TRUE) print_p(p)
print_p <- GGally::print_if_interactive library(ggplot2) # basic glyph map with reference line and box--------------- p <- ggplot(data = GGally::nasa, aes(x_major = long, x_minor = day, y_major = lat, y_minor = surftemp)) + geom_glyph_box() + geom_glyph_line() + geom_glyph() + theme_bw() print_p(p) # rescale on each individual glyph --------------- p <- ggplot(data = GGally::nasa, aes(x_major = long, x_minor = day, y_major = lat, y_minor = surftemp)) + geom_glyph(global_rescale = FALSE) print_p(p) # adjust width and height with relative & absolute value --------------- p <- ggplot() + geom_glyph(data = GGally::nasa, aes(x_major = long, x_minor = day, y_major = lat, y_minor = surftemp), width = rel(0.8), height = 1) + theme_bw() print_p(p) # apply a re-scaling on Y and use polar coordinate p <- GGally::nasa |> ggplot(aes(x_major = long, x_minor = day, y_major = lat, y_minor = ozone)) + geom_glyph_box(fill=NA) + geom_glyph_line() + geom_glyph(y_scale = GGally::range01, polar = TRUE) print_p(p)
Predicate functions on the object class
is_cubble(data) is_cubble_spatial(data) is_cubble_temporal(data) is_sf(data) is_tsibble(data)
is_cubble(data) is_cubble_spatial(data) is_cubble_temporal(data) is_sf(data) is_tsibble(data)
data |
an object to test for the class |
a logical value of TRUE/FALSE
is_cubble(stations) is_cubble(meteo) is_cubble(climate_flat) is_cubble(climate_mel) is_cubble(climate_aus) is_cubble_spatial(climate_aus) is_cubble_temporal(climate_aus)
is_cubble(stations) is_cubble(meteo) is_cubble(climate_flat) is_cubble(climate_mel) is_cubble(climate_aus) is_cubble_spatial(climate_aus) is_cubble_temporal(climate_aus)
Extract cubble attributes
## S3 method for class 'cubble_df' key_vars(x) ## S3 method for class 'cubble_df' key(x) ## S3 method for class 'cubble_df' key_data(.data) coords(data) spatial(data) ## S3 method for class 'spatial_cubble_df' spatial(data) ## S3 method for class 'temporal_cubble_df' spatial(data) index(data) index_var(data)
## S3 method for class 'cubble_df' key_vars(x) ## S3 method for class 'cubble_df' key(x) ## S3 method for class 'cubble_df' key_data(.data) coords(data) spatial(data) ## S3 method for class 'spatial_cubble_df' spatial(data) ## S3 method for class 'temporal_cubble_df' spatial(data) index(data) index_var(data)
x , .data , data
|
a cubble object |
library(tsibble) key(climate_mel) key_vars(climate_mel) key_data(climate_mel) cubble::index(climate_mel) cubble::index_var(climate_mel) coords(climate_mel) spatial(climate_mel)
library(tsibble) key(climate_mel) key_vars(climate_mel) key_data(climate_mel) cubble::index(climate_mel) cubble::index_var(climate_mel) coords(climate_mel) spatial(climate_mel)
add geometry list column to cubble_df object
make_spatial_sf(x, sfc = NULL, crs, silent = FALSE)
make_spatial_sf(x, sfc = NULL, crs, silent = FALSE)
x |
object of class |
sfc |
object of class |
crs |
object of class |
silent |
logical; suppress message? |
climate_mel |> make_spatial_sf()
climate_mel |> make_spatial_sf()
tbl_ts
)Update the temporal cubble to include the tsibble class (tbl_ts
)
make_temporal_tsibble(x)
make_temporal_tsibble(x)
x |
object of class |
climate_mel |> face_temporal() |> make_temporal_tsibble()
climate_mel |> face_temporal() |> make_temporal_tsibble()
The spatial matching is calculated using sf::st_distance()
with different
distance (in meter or degree) available depending on the coordinate reference
system and parameter (which
and par
). The temporal matching is based on
a temporal matching function (temporal_match_fn
) that can be customised.
match_sites( df1, df2, crs = sf::st_crs("OGC:CRS84"), which = NULL, par = 0, spatial_n_each = 1, spatial_n_group = 4, data_id, match_id, temporal_matching = TRUE, temporal_by, temporal_match_fn = match_peak, temporal_n_highest = 20, temporal_window = 5, ... ) match_spatial( df1, df2, crs = sf::st_crs("OGC:CRS84"), which = NULL, par = 0, spatial_n_each = 1, spatial_n_group = 4, return_cubble = FALSE ) match_temporal( data, data_id, match_id = NULL, temporal_by, return_cubble = FALSE, temporal_match_fn = match_peak, temporal_n_highest = 30, temporal_window = 5, ... )
match_sites( df1, df2, crs = sf::st_crs("OGC:CRS84"), which = NULL, par = 0, spatial_n_each = 1, spatial_n_group = 4, data_id, match_id, temporal_matching = TRUE, temporal_by, temporal_match_fn = match_peak, temporal_n_highest = 20, temporal_window = 5, ... ) match_spatial( df1, df2, crs = sf::st_crs("OGC:CRS84"), which = NULL, par = 0, spatial_n_each = 1, spatial_n_group = 4, return_cubble = FALSE ) match_temporal( data, data_id, match_id = NULL, temporal_by, return_cubble = FALSE, temporal_match_fn = match_peak, temporal_n_highest = 30, temporal_window = 5, ... )
df1 , df2
|
the two cubble objects to match |
crs |
a crs object from |
which |
character; for Cartesian coordinates only: one of |
par |
for |
spatial_n_each |
integer, the number of matched "station" in |
spatial_n_group |
integer, the number of matched group (pair) return |
data_id |
a character (or symbol), the variable differentiates
|
match_id |
a character (or symbol), the variable differentiate each group of match |
temporal_matching |
logical, whether to match temporally |
temporal_by |
in the |
temporal_match_fn |
character, the function name on how two time series should be matched |
temporal_n_highest |
numeric, the number of highest peak used for
temporal matching in |
temporal_window |
The temporal window allowed in |
... |
parameters passing to temporal match |
return_cubble |
logical (default to false), whether to return the cubble object or a matching summary table |
data |
the resulting cubble object from spatial matching (with
|
library(dplyr) climate_aus <- mutate(climate_aus, type = "climate") match_spatial(climate_aus, river) # turn with different distance calculation: match_spatial(climate_aus, river, which = "Hausdorff") # tune the number of matches in each group match_spatial(climate_aus, river, spatial_n_each = 5, spatial_n_group = 2) a1 <- match_spatial(climate_aus, river, return_cubble = TRUE) |> bind_rows() match_temporal(a1, data_id = type, match_id = group, temporal_by = c("prcp" = "Water_course_level"))
library(dplyr) climate_aus <- mutate(climate_aus, type = "climate") match_spatial(climate_aus, river) # turn with different distance calculation: match_spatial(climate_aus, river, which = "Hausdorff") # tune the number of matches in each group match_spatial(climate_aus, river, spatial_n_each = 5, spatial_n_group = 2) a1 <- match_spatial(climate_aus, river, return_cubble = TRUE) |> bind_rows() match_temporal(a1, data_id = type, match_id = group, temporal_by = c("prcp" = "Water_course_level"))
Print methods
## S3 method for class 'cubble_df' print(x, width = NULL, ...) ## S3 method for class 'spatial_cubble_df' tbl_sum(x) ## S3 method for class 'temporal_cubble_df' tbl_sum(x)
## S3 method for class 'cubble_df' print(x, width = NULL, ...) ## S3 method for class 'spatial_cubble_df' tbl_sum(x) ## S3 method for class 'temporal_cubble_df' tbl_sum(x)
x |
any R object (conceptually); typically numeric. |
width |
|
... |
further arguments passed to or from other methods. |
climate_mel # a nested/spatial cubble face_temporal(climate_mel) # a long/temporal cubble
climate_mel # a nested/spatial cubble face_temporal(climate_mel) # a long/temporal cubble
Australia river data
river
river
An object of class spatial_cubble_df
(inherits from cubble_df
, tbl_df
, tbl
, data.frame
) with 71 rows and 6 columns.
river
river
Daily measure (2020-01-01 to 2020-01-10) on precipitation (prcp),
maximum temperature (tmax), and minimum temperature (tmin)
for 3 melbourne airport stations. stations
is the spatial component,
(stations_sf
as an sf object), meteo
has the temporal component
(meteo_ts
as a tsibble object), climate_flat
has both
in a single joined table, and climate_mel
is the cubble object.
See climate_aus
on the full dataset.
stations stations_sf meteo meteo_ts climate_flat climate_mel
stations stations_sf meteo meteo_ts climate_flat climate_mel
An object of class tbl_df
(inherits from tbl
, data.frame
) with 3 rows and 6 columns.
An object of class sf
(inherits from tbl_df
, tbl
, data.frame
) with 3 rows and 5 columns.
An object of class tbl_df
(inherits from tbl
, data.frame
) with 30 rows and 5 columns.
An object of class tbl_ts
(inherits from tbl_df
, tbl
, data.frame
) with 30 rows and 5 columns.
An object of class tbl_df
(inherits from tbl
, data.frame
) with 30 rows and 10 columns.
An object of class spatial_cubble_df
(inherits from cubble_df
, tbl_df
, tbl
, data.frame
) with 3 rows and 7 columns.
climate_aus
cb <- make_cubble( spatial = stations, temporal = meteo, key = id, index = date, coords = c(long, lat) ) identical(cb, climate_mel) cb2 <- climate_flat |> as_cubble(key = id, index = date, coords = c(long, lat)) identical(cb, climate_mel)
cb <- make_cubble( spatial = stations, temporal = meteo, key = id, index = date, coords = c(long, lat) ) identical(cb, climate_mel) cb2 <- climate_flat |> as_cubble(key = id, index = date, coords = c(long, lat)) identical(cb, climate_mel)
Some spatio-temporal transformation, i.e. glyph maps, uses both spatial
and temporal variables. unfold()
allows you to temporarily moves spatial
variables into the long form for these transformations.
unfold(data, ...) ## S3 method for class 'spatial_cubble_df' unfold(data, ...) ## S3 method for class 'temporal_cubble_df' unfold(data, ...)
unfold(data, ...) ## S3 method for class 'spatial_cubble_df' unfold(data, ...) ## S3 method for class 'temporal_cubble_df' unfold(data, ...)
data |
a long cubble object |
... |
spatial variables to move into the long form, support tidyselect syntax |
a cubble object in the long form
climate_mel |> face_temporal() |> unfold(long, lat) climate_mel |> face_temporal() |> unfold(dplyr::starts_with("l"))
climate_mel |> face_temporal() |> unfold(long, lat) climate_mel |> face_temporal() |> unfold(dplyr::starts_with("l"))
When the data is already a cubble object but need update on attributes
update_cubble(data, key, index, coords, ...) ## S3 method for class 'spatial_cubble_df' update_cubble(data, key = NULL, index = NULL, coords = NULL, ...)
update_cubble(data, key, index, coords, ...) ## S3 method for class 'spatial_cubble_df' update_cubble(data, key = NULL, index = NULL, coords = NULL, ...)
data , key , index , coords , ...
|
see |