Title: | Exploration of Spatio-Temporal Data |
---|---|
Description: | A set of statistical tools for spatio-temporal data exploration. Includes simple plotting functions, covariance calculations and computations similar to principal component analysis for spatio-temporal data. Can use both dataframes and stars objects for all plots and computations. For more details refer 'Spatio-Temporal Statistics with R' (Christopher K. Wikle, Andrew Zammit-Mangion, Noel Cressie, 2019, ISBN:9781138711136). |
Authors: | Sevvandi Kandanaarachchi [aut, cre] , Petra Kuhnert [aut] , Andrew Zammit-Mangion [ctb] , Christopher Wikle [ctb] |
Maintainer: | Sevvandi Kandanaarachchi <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.0 |
Built: | 2024-11-17 06:27:52 UTC |
Source: | https://github.com/sevvandi/stxplore |
Aerosol optical thickness data from December 2019 to December 2020, taken monthly.
aerosol_australia
aerosol_australia
A stars object with x, y and time containing aerosol thickness. Dimensions 70x70x13.
Aerosol optical thickness data from December 2019 to December 2020, taken monthly.
aerosol_world
aerosol_world
A stars object with x, y and time containing aerosol thickness. Dimensions 360x180x13
Performs Canonical Correlation Analysis (CCA) using Empirical Orthogonal Function analysis using in a dataframe or a stars object. The autoplot function can plot the outputs.
The variations are * 'cancor_eof.data.frame()' if the input is a dataframe * 'cancor_eof.stars()' if the input is a stars object * 'autoplot.cancoreof()' to plot the outputs.
cancor_eof(x, lag, n_eof, ...) ## S3 method for class 'data.frame' cancor_eof(x, lag = 7, n_eof = 10, values_df, ...) ## S3 method for class 'stars' cancor_eof(x, lag = 7, n_eof = 10, ...) ## S3 method for class 'cancoreof' autoplot( object, line_plot = TRUE, space_plot = TRUE, palette = "Spectral", xlab = "Time", ... )
cancor_eof(x, lag, n_eof, ...) ## S3 method for class 'data.frame' cancor_eof(x, lag = 7, n_eof = 10, values_df, ...) ## S3 method for class 'stars' cancor_eof(x, lag = 7, n_eof = 10, ...) ## S3 method for class 'cancoreof' autoplot( object, line_plot = TRUE, space_plot = TRUE, palette = "Spectral", xlab = "Time", ... )
x |
The dataframe or stars object. If it is a dataframe, then it should have the locations. |
lag |
Specifies the lag to be used. |
n_eof |
The number of EOFs to be used. |
... |
Other arguments currently ignored. |
values_df |
For dataframes: the dataframe of dimension |
object |
autoplot parameter: the output of the function ‘cancor_eof’. |
line_plot |
autoplot parameter: if set to |
space_plot |
autoplot parameter: if set to |
palette |
autoplot parameter: the color palette to use for plotting. |
xlab |
autoplot parameter:: he label on the x-axis for the line plot. |
A cancoreof object with CCA output, EOF output, original data and cancor object from 'stats'.
# Dataframe example data(SSTlonlatshort) data(SSTdatashort) cancor_df <- cancor_eof(x = SSTlonlatshort, lag = 7, n_eof = 8, values_df = SSTdatashort) autoplot(cancor_df) # Stars example library(dplyr) library(stars) # Create a stars object from a data frame precip_df <- NOAA_df_1990[NOAA_df_1990$proc == 'Precip', ] %>% filter(date >= "1992-02-01" & date <= "1992-02-28") precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')] st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date")) cancor_st <- cancor_eof(st_precip) autoplot(cancor_st, line_plot = TRUE, space_plot = FALSE)
# Dataframe example data(SSTlonlatshort) data(SSTdatashort) cancor_df <- cancor_eof(x = SSTlonlatshort, lag = 7, n_eof = 8, values_df = SSTdatashort) autoplot(cancor_df) # Stars example library(dplyr) library(stars) # Create a stars object from a data frame precip_df <- NOAA_df_1990[NOAA_df_1990$proc == 'Precip', ] %>% filter(date >= "1992-02-01" & date <= "1992-02-28") precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')] st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date")) cancor_st <- cancor_eof(st_precip) autoplot(cancor_st, line_plot = TRUE, space_plot = FALSE)
Computes Canonical Correlation Analysis (CCA) using 2 datasets. The autoplot function plots the output.
canonical_correlation(x1, x2, ...) ## S3 method for class 'data.frame' canonical_correlation(x1, x2, ...) ## S3 method for class 'stars' canonical_correlation(x1, x2, ...) ## S3 method for class 'cancor' autoplot(object, xlab = "Time", ...)
canonical_correlation(x1, x2, ...) ## S3 method for class 'data.frame' canonical_correlation(x1, x2, ...) ## S3 method for class 'stars' canonical_correlation(x1, x2, ...) ## S3 method for class 'cancor' autoplot(object, xlab = "Time", ...)
x1 |
The first dataframe or stars object. |
x2 |
The second dataframe or stars objext. The dimensions of both datasets need to be the same. |
... |
Other arguments currently ignored. |
object |
For autoplot: the output of the function ‘cannonical_correlation’. |
xlab |
For autoplot: the xlabel to appear on CCA plot. |
A canonical correlation object.
# Dataframe example df1 <- SSTdatashort[1:100, ] df2 <- SSTdatashort[401:500, ] ccor <- canonical_correlation(df1, df2) autoplot(ccor) # stars example library(stars) tif = system.file("tif/olinda_dem_utm25s.tif", package = "stars") x <- read_stars(tif) x1 <- x[[1]][1:50, 1:50] x2 <- x[[1]][51:100, 1:50] stx1 <- st_as_stars(x1) stx2 <- st_as_stars(x2) canonical_correlation(stx1, stx2)
# Dataframe example df1 <- SSTdatashort[1:100, ] df2 <- SSTdatashort[401:500, ] ccor <- canonical_correlation(df1, df2) autoplot(ccor) # stars example library(stars) tif = system.file("tif/olinda_dem_utm25s.tif", package = "stars") x <- read_stars(tif) x1 <- x[[1]][1:50, 1:50] x2 <- x[[1]][51:100, 1:50] stx1 <- st_as_stars(x1) stx2 <- st_as_stars(x2) canonical_correlation(stx1, stx2)
Computes empirical orthogonal functions of the data. Function autoplot can plot the output.
emp_orth_fun(x, ...) ## S3 method for class 'data.frame' emp_orth_fun(x, values_df, ...) ## S3 method for class 'stars' emp_orth_fun(x, ...) ## S3 method for class 'emporthfun' autoplot( object, EOF_num = 1, palette = "Spectral", only_EOF = FALSE, only_TS = FALSE, ... )
emp_orth_fun(x, ...) ## S3 method for class 'data.frame' emp_orth_fun(x, values_df, ...) ## S3 method for class 'stars' emp_orth_fun(x, ...) ## S3 method for class 'emporthfun' autoplot( object, EOF_num = 1, palette = "Spectral", only_EOF = FALSE, only_TS = FALSE, ... )
x |
The dataframe or stars object. If it is a dataframe, then it should have the locations. |
... |
Other arguments currently ignored. |
values_df |
For dataframes: the dataframe of dimension |
object |
For autoplot: the output of the function ‘emp_orth_fun’. |
EOF_num |
For autoplot: the number of Empirical Orthogonal Functions (EOFs) to plot. |
palette |
The color palette. Default is |
only_EOF |
For autoplot: if |
only_TS |
For autoplot: if |
An emporthfun object with temporal PCs and spatial EOFs.
# dataframe example data(SSTlonlatshort) data(SSTdatashort) data(SSTlandmaskshort) delete_rows <- which(SSTlandmaskshort == 1) SSTdatashort <- SSTdatashort[-delete_rows, 1:396] emp1 <- emp_orth_fun(SSTlonlatshort[-delete_rows, ], SSTdatashort) autoplot(emp1, EOF_num = 1) # stars example library(dplyr) library(stars) # Create a stars object from a data frame precip_df <- NOAA_df_1990[NOAA_df_1990$proc == 'Precip', ] %>% filter(date >= "1992-02-01" & date <= "1992-02-05") precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')] st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date")) emp <- emp_orth_fun(st_precip) autoplot(emp, only_TS = TRUE)
# dataframe example data(SSTlonlatshort) data(SSTdatashort) data(SSTlandmaskshort) delete_rows <- which(SSTlandmaskshort == 1) SSTdatashort <- SSTdatashort[-delete_rows, 1:396] emp1 <- emp_orth_fun(SSTlonlatshort[-delete_rows, ], SSTdatashort) autoplot(emp1, EOF_num = 1) # stars example library(dplyr) library(stars) # Create a stars object from a data frame precip_df <- NOAA_df_1990[NOAA_df_1990$proc == 'Precip', ] %>% filter(date >= "1992-02-01" & date <= "1992-02-05") precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')] st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date")) emp <- emp_orth_fun(st_precip) autoplot(emp, only_TS = TRUE)
Computes empirical spatial covariance by removing trends and examining residuals. It can compute lag-0 or log-1 empirical covariance either by latitude or longitude. You can split up the spatial domain by latitude or longitude and plot the covariance for each longitudinal/latitudinal strips.
emp_spatial_cov( x, lat_or_lon_strips = "lon", quadratic_time = FALSE, quadratic_space = FALSE, num_strips = 1, lag = 0, ... ) ## S3 method for class 'data.frame' emp_spatial_cov( x, lat_or_lon_strips = "lon", quadratic_time = FALSE, quadratic_space = FALSE, num_strips = 1, lag = 0, lat_col, lon_col, t_col, z_col, ... ) ## S3 method for class 'stars' emp_spatial_cov( x, lat_or_lon_strips = "lon", quadratic_time = FALSE, quadratic_space = FALSE, num_strips = 1, lag = 0, ... ) ## S3 method for class 'spatialcov' autoplot(object, xlab = "Latitude", ...)
emp_spatial_cov( x, lat_or_lon_strips = "lon", quadratic_time = FALSE, quadratic_space = FALSE, num_strips = 1, lag = 0, ... ) ## S3 method for class 'data.frame' emp_spatial_cov( x, lat_or_lon_strips = "lon", quadratic_time = FALSE, quadratic_space = FALSE, num_strips = 1, lag = 0, lat_col, lon_col, t_col, z_col, ... ) ## S3 method for class 'stars' emp_spatial_cov( x, lat_or_lon_strips = "lon", quadratic_time = FALSE, quadratic_space = FALSE, num_strips = 1, lag = 0, ... ) ## S3 method for class 'spatialcov' autoplot(object, xlab = "Latitude", ...)
x |
A stars object or a dataframe. Arguments differ according to the input type. |
lat_or_lon_strips |
Takes the values |
quadratic_time |
If |
quadratic_space |
If |
num_strips |
The number of latitudinal/longitudinal strips to produce. This is used when plotting using autoplot. |
lag |
Lag can be either 0 or 1. |
... |
Other arguments currently ignored. |
lat_col |
For dataframes: the column or the column name giving the latitude. The y coordinate can be used instead of latitude. |
lon_col |
For dataframes: the column or the column name giving the longitude. The x coordinate can be used instead of longitude. |
t_col |
For dataframes: the time column. Time must be a set of discrete integer values. |
z_col |
For dataframes: the The quantity of interest that will be plotted. Eg. temperature. |
object |
For autoplot: the output of the function ‘emp_spatial_cov’. |
xlab |
For autoplot: the label for x-axis. |
A spatialcov object with empirical covariance data organised spatially according to the number of strips and the lagged covariance.
# Dataframe example library(dplyr) data(NOAA_df_1990) Tmax <- filter(NOAA_df_1990, proc == "Tmax" & month %in% 5:6 & year == 1993) Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 emp_df <- emp_spatial_cov(Tmax, lat_col = "lat", lon_col = "lon", t_col ="t", z_col = "z", lat_or_lon_strips = "lon", num_strips = 4, lag = 1) autoplot(emp_df) # Stars example library(stars) # Create a stars object from a data frame precip_df <- NOAA_df_1990[NOAA_df_1990$proc == 'Precip', ] %>% filter(date >= "1992-02-01" & date <= "1992-02-05") precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')] st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date")) emp_spatial_cov(st_precip)
# Dataframe example library(dplyr) data(NOAA_df_1990) Tmax <- filter(NOAA_df_1990, proc == "Tmax" & month %in% 5:6 & year == 1993) Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 emp_df <- emp_spatial_cov(Tmax, lat_col = "lat", lon_col = "lon", t_col ="t", z_col = "z", lat_or_lon_strips = "lon", num_strips = 4, lag = 1) autoplot(emp_df) # Stars example library(stars) # Create a stars object from a data frame precip_df <- NOAA_df_1990[NOAA_df_1990$proc == 'Precip', ] %>% filter(date >= "1992-02-01" & date <= "1992-02-05") precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')] st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date")) emp_spatial_cov(st_precip)
This function creates the data structure for Hovmoller plots for either latitude or longitude. This function can take either a stars object or a dataframe. Input arguments differ for each case. The function autoplot can plot this object.
hovmoller(x, lat_or_lon = "lat", xlen = NULL, ...) ## S3 method for class 'data.frame' hovmoller( x, lat_or_lon = "lat", xlen = NULL, lat_or_lon_col, t_col, z_col, ... ) ## S3 method for class 'stars' hovmoller(x, lat_or_lon = "lat", xlen = NULL, ...) ## S3 method for class 'hovmoller' autoplot( object, ylab = "Day", xlab = NULL, title = "", palette = "Spectral", legend_title = "z", ... )
hovmoller(x, lat_or_lon = "lat", xlen = NULL, ...) ## S3 method for class 'data.frame' hovmoller( x, lat_or_lon = "lat", xlen = NULL, lat_or_lon_col, t_col, z_col, ... ) ## S3 method for class 'stars' hovmoller(x, lat_or_lon = "lat", xlen = NULL, ...) ## S3 method for class 'hovmoller' autoplot( object, ylab = "Day", xlab = NULL, title = "", palette = "Spectral", legend_title = "z", ... )
x |
A stars object or a dataframe. Arguments differ according to the input type. |
lat_or_lon |
Needs to be either |
xlen |
The length of the xaxis for latitude/longitude. |
... |
Other arguments currently ignored. |
lat_or_lon_col |
For dataframes: the column or the column name corresponding to the latitude/longitude. |
t_col |
For dataframes: the time column. Time must be a set of discrete integer values. |
z_col |
For dataframes: the The quantity of interest that will be plotted. Eg. temperature. |
object |
For autoplot: the output of the function ‘hovmoller’. |
ylab |
The y label. |
xlab |
The x label. |
title |
The graph title. |
palette |
The color palette. Default is |
legend_title |
The title for the legend. |
An object of hovmoller class containing the original data and the Hovmoller data.
# dataframe examples library(dplyr) data(NOAA_df_1990) Tmax <- filter(NOAA_df_1990, proc == "Tmax" & month %in% 5:9 & year == 1993 & id < 4000) Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 hov <- hovmoller(lat_or_lon = "lat", x = Tmax, lat_or_lon_col = 'lat', t_col = 't', z_col = 'z') autoplot(hov) # stars examples library(stars) prec_file = system.file("nc/test_stageiv_xyt.nc", package = "stars") prec <- read_ncdf(prec_file) prec2 <- prec %>% slice(time, 1:5) hov <- hovmoller(prec2) hov
# dataframe examples library(dplyr) data(NOAA_df_1990) Tmax <- filter(NOAA_df_1990, proc == "Tmax" & month %in% 5:9 & year == 1993 & id < 4000) Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 hov <- hovmoller(lat_or_lon = "lat", x = Tmax, lat_or_lon_col = 'lat', t_col = 't', z_col = 'z') autoplot(hov) # stars examples library(stars) prec_file = system.file("nc/test_stageiv_xyt.nc", package = "stars") prec <- read_ncdf(prec_file) prec2 <- prec %>% slice(time, 1:5) hov <- hovmoller(prec2) hov
This dataset is included in the STRbook R package.
locs
locs
A data frame with 328 rows and 3 variables:
Location is
Latitude
Longitude
...
A dataset containing the precipitation, maximum and minimum temperatures taken from the STRbook R package.
NOAA_df_1990
NOAA_df_1990
A data frame with 53940 rows and 10 variables:
Day in Julian time
The year
The month
The day
The location id
The value
The type of observation
Latitude
Longitude
The date
...
Plots ridgeline plots grouped by latitude/longitude or time. This function can take either a stars object or a dataframe. Input arguments differ for each case.
ridgeline( x, num_grps = 10, xlab = "Value", ylab = "Group Intervals", title = "", legend_title = "z", ... ) ## S3 method for class 'data.frame' ridgeline( x, num_grps = 10, xlab = "Value", ylab = "Group Intervals", title = "", legend_title = "z", group_col, z_col, ... ) ## S3 method for class 'stars' ridgeline( x, num_grps = 10, xlab = "Value", ylab = "Group Intervals", title = "", legend_title = "z", group_dim, ... )
ridgeline( x, num_grps = 10, xlab = "Value", ylab = "Group Intervals", title = "", legend_title = "z", ... ) ## S3 method for class 'data.frame' ridgeline( x, num_grps = 10, xlab = "Value", ylab = "Group Intervals", title = "", legend_title = "z", group_col, z_col, ... ) ## S3 method for class 'stars' ridgeline( x, num_grps = 10, xlab = "Value", ylab = "Group Intervals", title = "", legend_title = "z", group_dim, ... )
x |
A stars object or a dataframe. Arguments differ according to the input type. |
num_grps |
The number of levels for the ridgeline plot. |
xlab |
The x label. |
ylab |
The y label. |
title |
The graph title. |
legend_title |
The title for the legend. |
... |
Other arguments currently ignored. |
group_col |
For dataframes: the column name of the group column. |
z_col |
For dataframes: the The quantity of interest that will be plotted. Eg. temperature. |
group_dim |
For stars objects: the dimension for the grouping variable. |
A ggplot object.
# Dataframe example library(dplyr) data(NOAA_df_1990) TmaxJan <- filter(NOAA_df_1990, proc == "Tmax" & year == 1993 & month == 1) ridgeline(TmaxJan, group_col = 'lat', z_col = 'z', xlab = 'Maximum Temperature', ylab = 'Latitude Intervals') # stars examples library(stars) library(units) # stars Example 1 tif = system.file("tif/olinda_dem_utm25s.tif", package = "stars") x <- read_stars(tif) dim(x) ridgeline(x, group_dim = 1) ridgeline(x, group_dim = 2) # stars Example 2 tif = system.file("tif/lc.tif", package = "stars") x <- read_stars(tif) ridgeline(x, group_dim = 1) ridgeline(x, group_dim = 2)
# Dataframe example library(dplyr) data(NOAA_df_1990) TmaxJan <- filter(NOAA_df_1990, proc == "Tmax" & year == 1993 & month == 1) ridgeline(TmaxJan, group_col = 'lat', z_col = 'z', xlab = 'Maximum Temperature', ylab = 'Latitude Intervals') # stars examples library(stars) library(units) # stars Example 1 tif = system.file("tif/olinda_dem_utm25s.tif", package = "stars") x <- read_stars(tif) dim(x) ridgeline(x, group_dim = 1) ridgeline(x, group_dim = 2) # stars Example 2 tif = system.file("tif/lc.tif", package = "stars") x <- read_stars(tif) ridgeline(x, group_dim = 1) ridgeline(x, group_dim = 2)
Computes the semi-variogram from a stars or a dataframe. Input arguments differ for each case. Function autoplot can plot the output.
When the input is a dataframe, the locations, time and the quantity of interest needs to be given. When the input is a stars object, a 3 dimensional stars object needs to be given as input with the first 2 dimensions being spatial and the third being time.
semivariogram( x, latitude_linear = TRUE, longitude_linear = TRUE, missing_value = -9999, width = 80, cutoff = 1000, tlagmax = 6, ... ) ## S3 method for class 'data.frame' semivariogram( x, latitude_linear = TRUE, longitude_linear = TRUE, missing_value = -9999, width = 80, cutoff = 1000, tlagmax = 6, times_df, values_df, ... ) ## S3 method for class 'stars' semivariogram( x, latitude_linear = TRUE, longitude_linear = TRUE, missing_value = -9999, width = 80, cutoff = 1000, tlagmax = 6, ... ) ## S3 method for class 'semivariogramobj' autoplot(object, ...)
semivariogram( x, latitude_linear = TRUE, longitude_linear = TRUE, missing_value = -9999, width = 80, cutoff = 1000, tlagmax = 6, ... ) ## S3 method for class 'data.frame' semivariogram( x, latitude_linear = TRUE, longitude_linear = TRUE, missing_value = -9999, width = 80, cutoff = 1000, tlagmax = 6, times_df, values_df, ... ) ## S3 method for class 'stars' semivariogram( x, latitude_linear = TRUE, longitude_linear = TRUE, missing_value = -9999, width = 80, cutoff = 1000, tlagmax = 6, ... ) ## S3 method for class 'semivariogramobj' autoplot(object, ...)
x |
The dataframe or stars object. If it is a dataframe, then it should have the locations. |
latitude_linear |
If |
longitude_linear |
If |
missing_value |
If a certain value such as -9999 denotes the missing values for given locations and times. |
width |
A parameter to the |
cutoff |
A parameter to the |
tlagmax |
A parameter to the |
... |
Other arguments that need to be used for datafames or currently ignored. |
times_df |
For dataframes: the dataframe containing the dates in |
values_df |
For dataframes: the dataframe of dimension |
object |
For autoplot: the output from the semivariogram function. |
A semivariogram object with a gstat variogram and the original data.
# Dataframe example library(dplyr) data(locs) data(Times) data(Tmax) temp_part <- with(Times, paste(year, month, day, sep = "-")) temp_part <- data.frame(date = as.Date(temp_part)[913:923]) Tmax <- Tmax[913:923, ] semidf <- semivariogram(locs, temp_part, Tmax, latitude_linear = FALSE, longitude_linear = FALSE, missing_value = -9999, width = 50, cutoff = 1000, tlagmax = 7 ) autoplot(semidf) # Stars example library(stars) # Create a stars object from a data frame precip_df <- NOAA_df_1990[NOAA_df_1990$proc == 'Precip', ] %>% filter(date >= "1992-02-01" & date <= "1992-02-05") precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')] st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date")) semist <- semivariogram(st_precip) autoplot(semist)
# Dataframe example library(dplyr) data(locs) data(Times) data(Tmax) temp_part <- with(Times, paste(year, month, day, sep = "-")) temp_part <- data.frame(date = as.Date(temp_part)[913:923]) Tmax <- Tmax[913:923, ] semidf <- semivariogram(locs, temp_part, Tmax, latitude_linear = FALSE, longitude_linear = FALSE, missing_value = -9999, width = 50, cutoff = 1000, tlagmax = 7 ) autoplot(semidf) # Stars example library(stars) # Create a stars object from a data frame precip_df <- NOAA_df_1990[NOAA_df_1990$proc == 'Precip', ] %>% filter(date >= "1992-02-01" & date <= "1992-02-05") precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')] st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date")) semist <- semivariogram(st_precip) autoplot(semist)
This function computes spatial empirical means by latitude and longitude averaged over time. This function can take either a stars object or a dataframe. Input arguments differ for each case. The autoplot function can plot this object.
The variations are * 'spatial_means.data.frame()' if the input is a dataframe * 'spatial_means.stars()' if the input is a stars object * 'autoplot.spatialmeans()' to plot the outputs.
spatial_means(x, ...) ## S3 method for class 'data.frame' spatial_means(x, lat_col, lon_col, t_col, z_col, ...) ## S3 method for class 'stars' spatial_means(x, ...) ## S3 method for class 'spatialmeans' autoplot( object, ylab = "Mean Value", xlab1 = "Latitude", xlab2 = "Longitude", title = "Spatial Empirical Means", ... )
spatial_means(x, ...) ## S3 method for class 'data.frame' spatial_means(x, lat_col, lon_col, t_col, z_col, ...) ## S3 method for class 'stars' spatial_means(x, ...) ## S3 method for class 'spatialmeans' autoplot( object, ylab = "Mean Value", xlab1 = "Latitude", xlab2 = "Longitude", title = "Spatial Empirical Means", ... )
x |
A stars object or a dataframe. Arguments differ according to the input type. |
... |
Other arguments currently ignored. |
lat_col |
For dataframes: the column or the column name giving the latitude. The y coordinate can be used instead of latitude. |
lon_col |
For dataframes: the column or the column name giving the longitude. The x coordinate can be used instead of longitude. |
t_col |
For dataframes: the time column. Time must be a set of discrete integer values. |
z_col |
For dataframes: the The quantity of interest that will be plotted. Eg. temperature. |
object |
For autoplot: the output from the ‘spatial_means’ function. |
ylab |
For autoplot: the ylabel. |
xlab1 |
For autoplot: The xlabel for the first plot. |
xlab2 |
For autuoplot: The xlabel for the second plot. |
title |
The graph title. |
A spatialmeans object contaiing spatial averages and the original data.
# dataframe example data(NOAA_df_1990) library(dplyr) Tmax <- filter(NOAA_df_1990, # subset the data proc == "Tmax" & # extract max temperature month %in% 5:9 & # May to July year == 1993) # year 1993 Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 # create a new time variable starting at 1 sp_df <- spatial_means(Tmax, lat_col = "lat", lon_col = "lon", t_col = "t", z_col = "z") autoplot(sp_df) # stars examples library(stars) tif = system.file("tif/olinda_dem_utm25s.tif", package = "stars") x <- read_stars(tif) sp_means <- spatial_means(x) autoplot(sp_means)
# dataframe example data(NOAA_df_1990) library(dplyr) Tmax <- filter(NOAA_df_1990, # subset the data proc == "Tmax" & # extract max temperature month %in% 5:9 & # May to July year == 1993) # year 1993 Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 # create a new time variable starting at 1 sp_df <- spatial_means(Tmax, lat_col = "lat", lon_col = "lon", t_col = "t", z_col = "z") autoplot(sp_df) # stars examples library(stars) tif = system.file("tif/olinda_dem_utm25s.tif", package = "stars") x <- read_stars(tif) sp_means <- spatial_means(x) autoplot(sp_means)
This function can take either a stars object or a dataframe. Input arguments differ for each case.
For dataframes, usage involves latitude and longitude. However, x and y coordinates can be given instead of longitude and latitude. If x and y are given instead of longitude and latitude, the country borders will not be shown.
spatial_snapshots( x, xlab = "x", ylab = "y", title = "", palette = "Spectral", legend_title = "z", ... ) ## S3 method for class 'data.frame' spatial_snapshots( x, xlab = "Longitude", ylab = "Latitude", title = "", palette = "Spectral", legend_title = "z", lat_col, lon_col, t_col, z_col, ifxy = FALSE, ... ) ## S3 method for class 'stars' spatial_snapshots( x, xlab = "x", ylab = "y", title = "", palette = "Spectral", legend_title = "z", ... )
spatial_snapshots( x, xlab = "x", ylab = "y", title = "", palette = "Spectral", legend_title = "z", ... ) ## S3 method for class 'data.frame' spatial_snapshots( x, xlab = "Longitude", ylab = "Latitude", title = "", palette = "Spectral", legend_title = "z", lat_col, lon_col, t_col, z_col, ifxy = FALSE, ... ) ## S3 method for class 'stars' spatial_snapshots( x, xlab = "x", ylab = "y", title = "", palette = "Spectral", legend_title = "z", ... )
x |
A stars object or a dataframe. Arguments differ according to the input type. |
xlab |
The x label. |
ylab |
The y label. |
title |
The graph title. |
palette |
The color palette. Default is |
legend_title |
The title for the legend. |
... |
Other arguments currently ignored. |
lat_col |
For dataframes: the column or the column name giving the latitude. The y coordinate can be used instead of latitude. |
lon_col |
For dataframes: the column or the column name giving the longitude. The x coordinate can be used instead of longitude. |
t_col |
For dataframes: the time column. Time must be a set of discrete integer values. |
z_col |
For dataframes: the The quantity of interest that will be plotted. Eg. temperature. |
ifxy |
For dataframes: if |
A ggplot object.
library(dplyr) # Dataframe example data(NOAA_df_1990) Tmax <- filter(NOAA_df_1990, proc == "Tmax" & month == 5 & year == 1993 & id < 4000) Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 Tmax_days <- subset(Tmax, t %in% c(1, 15)) spatial_snapshots(Tmax_days, lat_col = 'lat', lon_col = 'lon', t_col = 't', z_col = 'z', title = "Maximum Temperature for 2 days ") # stars example library(stars) tif = system.file("tif/L7_ETMs.tif", package = "stars") x <- read_stars(tif) x2 <- x %>% slice(band, 1:2) spatial_snapshots(x2)
library(dplyr) # Dataframe example data(NOAA_df_1990) Tmax <- filter(NOAA_df_1990, proc == "Tmax" & month == 5 & year == 1993 & id < 4000) Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 Tmax_days <- subset(Tmax, t %in% c(1, 15)) spatial_snapshots(Tmax_days, lat_col = 'lat', lon_col = 'lon', t_col = 't', z_col = 'z', title = "Maximum Temperature for 2 days ") # stars example library(stars) tif = system.file("tif/L7_ETMs.tif", package = "stars") x <- read_stars(tif) x2 <- x %>% slice(band, 1:2) spatial_snapshots(x2)
The original dataset is included in the STRbook R package.
SSTdatashort
SSTdatashort
A dataframe with 500 rows and 396 columns.
The original dataset is included in the STRbook R package.
SSTlandmaskshort
SSTlandmaskshort
A dataframe with 500 rows and 1 column.
A value of 1 is given if the location covers land.
...
The original dataset is included in the STRbook R package.
SSTlonlatshort
SSTlonlatshort
A data frame with 500 rows and 2 variables:
Longitude
Latitude
...
This function computes temporal empirical means averaged per time unit. This function can take either a stars object or a dataframe. Input arguments differ for each case. The function autoplot plots the output.
temporal_means(x, ...) ## S3 method for class 'data.frame' temporal_means(x, t_col, z_col, id_col, ...) ## S3 method for class 'stars' temporal_means(x, ...) ## S3 method for class 'temporalmeans' autoplot( object, ylab = "Value", xlab = "Time", legend_title = "", title = "Temporal Empirical Means", ... )
temporal_means(x, ...) ## S3 method for class 'data.frame' temporal_means(x, t_col, z_col, id_col, ...) ## S3 method for class 'stars' temporal_means(x, ...) ## S3 method for class 'temporalmeans' autoplot( object, ylab = "Value", xlab = "Time", legend_title = "", title = "Temporal Empirical Means", ... )
x |
A stars object or a dataframe. Arguments differ according to the input type. |
... |
Other arguments currently ignored. |
t_col |
For dataframes: the time column. Time must be a set of discrete integer values. |
z_col |
For dataframes: the The quantity of interest that will be plotted. Eg. temperature. |
id_col |
The column of the location id. |
object |
For autoplot: the output of the function ‘temporal_means’. |
ylab |
The y label. |
xlab |
The x label. |
legend_title |
For autoplot: the title for the legend. |
title |
The graph title. |
An object of class temporalmeans containing the averages and the original data in two dataframes.
# dataframe example data(NOAA_df_1990) library(dplyr) Tmax <- filter(NOAA_df_1990, # subset the data proc == "Tmax" & # extract max temperature month %in% 5:9 & # May to July year == 1993) # year 1993 Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 # create a new time variable starting at 1 tem <- temporal_means(Tmax, t_col = 'date', z_col = 'z', id_col = 'id') autoplot(tem) # stars example library(stars) library(dplyr) library(units) # Example prec_file = system.file("nc/test_stageiv_xyt.nc", package = "stars") prec <- read_ncdf(prec_file) temporal_means(prec)
# dataframe example data(NOAA_df_1990) library(dplyr) Tmax <- filter(NOAA_df_1990, # subset the data proc == "Tmax" & # extract max temperature month %in% 5:9 & # May to July year == 1993) # year 1993 Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 # create a new time variable starting at 1 tem <- temporal_means(Tmax, t_col = 'date', z_col = 'z', id_col = 'id') autoplot(tem) # stars example library(stars) library(dplyr) library(units) # Example prec_file = system.file("nc/test_stageiv_xyt.nc", package = "stars") prec <- read_ncdf(prec_file) temporal_means(prec)
This function plots temporal snapshos for specific spatial locations. The location id sample need to be given as a function argument.
temporal_snapshots(x, xlab = "x", ylab = "y", title = "", ...) ## S3 method for class 'data.frame' temporal_snapshots( x, xlab = "Time", ylab = "Value", title = "", t_col, z_col, id_col, id_sample, ... ) ## S3 method for class 'stars' temporal_snapshots( x, xlab = "Time", ylab = "Value", title = "", xvals, yvals, precision = 0, ... )
temporal_snapshots(x, xlab = "x", ylab = "y", title = "", ...) ## S3 method for class 'data.frame' temporal_snapshots( x, xlab = "Time", ylab = "Value", title = "", t_col, z_col, id_col, id_sample, ... ) ## S3 method for class 'stars' temporal_snapshots( x, xlab = "Time", ylab = "Value", title = "", xvals, yvals, precision = 0, ... )
x |
A stars object or a dataframe. Arguments differ according to the input type. |
xlab |
The x label. |
ylab |
The y label. |
title |
The graph title. |
... |
Other arguments currently ignored. |
t_col |
For dataframes: the time column. Time must be a set of discrete integer values. |
z_col |
For dataframes: the The quantity of interest that will be plotted. Eg. temperature. |
id_col |
The column of the location id. |
id_sample |
The sample of location ids to be plotted |
xvals |
For stars objects: the set of xvalues to plot. |
yvals |
For stars objects: the set of yvalues to plot. These two lengths need to be the same. |
precision |
For stars objects: set to 0, if the given values are compared with the integer values in the stars object. |
A ggplot.
# Dataframe example library(dplyr) data(NOAA_df_1990) Tmax <- filter(NOAA_df_1990, proc == "Tmax" & month %in% 5:9 & year == 1993) Tmax_ID <- unique(Tmax$id) Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 ids <- sample(Tmax_ID, 10) temporal_snapshots(Tmax, t_col = 't', z_col = 'z', id_col = 'id', id_sample = ids) # stars example library(stars) tif = system.file("tif/L7_ETMs.tif", package = "stars") x <- read_stars(tif) xvals <- c(288876.0,289047.0) yvals <- c(9120405, 9120006) temporal_snapshots(x, xvals = xvals, yvals = yvals)
# Dataframe example library(dplyr) data(NOAA_df_1990) Tmax <- filter(NOAA_df_1990, proc == "Tmax" & month %in% 5:9 & year == 1993) Tmax_ID <- unique(Tmax$id) Tmax$t <- Tmax$julian - min(Tmax$julian) + 1 ids <- sample(Tmax_ID, 10) temporal_snapshots(Tmax, t_col = 't', z_col = 'z', id_col = 'id', id_sample = ids) # stars example library(stars) tif = system.file("tif/L7_ETMs.tif", package = "stars") x <- read_stars(tif) xvals <- c(288876.0,289047.0) yvals <- c(9120405, 9120006) temporal_snapshots(x, xvals = xvals, yvals = yvals)
This dataset is included in the STRbook R package.
Times
Times
A data frame with 1461 rows and 4 variables:
Day in Julian time
The year
The month
The day
...
This dataset is included in the STRbook R package.
Tmax
Tmax
A data frame with 1461 rows and columns having maximum temperature for times and locations in data locs and Times.