Computes empirical orthogonal functions using a dataframe or a stars object.
Computes empirical orthogonal functions using a dataframe or a stars object.
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,...)
Arguments
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 length(times) x length(locations) containing the quantity of interest.
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 Spectral.
only_EOF: For autoplot: if TRUE, only the spatial EOF function would be plotted.
only_TS: For autoplot: if TRUE, only the PC time series would be plotted. If both are set to FALSE, both plots would be displayed. Both cannot be set to TRUE.
Returns
An emporthfun object with temporal PCs and spatial EOFs.
Examples
# dataframe exampledata(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 examplelibrary(dplyr)library(stars)# Create a stars object from a data frameprecip_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)