# NOT RUN {
#Setup
library(rtsVis)
library(ggplot2)
# Load example dataset at a greatly increased interval
x_list <- MODIS_SI_ds[seq(1,length(MODIS_SI_ds),30)]
x_dates <- do.call(c, lapply(MODIS_SI_ds,attr,"time") )[seq(1,length(MODIS_SI_ds),30)]
#Fill NAs
x_list_filled <- ts_fill_na(x_list)
#Make a sequence of output dates, double the length of input dates
out_dates <-seq.POSIXt(from = x_dates[1],
to = x_dates[length(x_dates)],length.out = length(x_dates)*2 )
#For each output date, interpolate a raster image from the input files
r_list_out <- ts_raster(r_list = x_list_filled,
r_times = x_dates,
out_times = out_dates,
fade_raster = TRUE)
#Create the frames
# as from the desired layers
r_frames <- ts_makeframes(x_list = r_list_out,samplesize = 10,
l_indices = c(1,4,3))
#optional: Use moveVis functions to add additional elements to our frames
#library(magrittr)
# r_frames <- r_frames %>%
# moveVis::add_labels(x = "Longitude", y = "Latitude")%>%
# moveVis::add_northarrow(colour = "white", position = "bottomright") %>%
# moveVis::add_timestamps(type = "label") %>%
# moveVis::add_progress()
#### Add the polygons
# Add polygons to the frames
polygons <- SI_positions$polygons #Polygons of Slovenian municipalities covered by the raster
r_frames_style_poly <-
ts_add_positions_to_frames(
r_frame_list = r_frames,
positions = polygons,
psize = 1,
pcol = "red",
position_names = c("Radece", "Ljubljana", "Kocevje"),
position_legend_title = "Obcina",
legend_position = "left",
aes_by_pos = FALSE
)
#Look at one of the new frames
r_frames_style_poly[5]
#Alternatively add points
points <- SI_positions$points #Points in Slovenia
r_frames_style_point <- rtsVis::ts_add_positions_to_frames(r_frame_list = r_frames,
positions = points,
psize = 4,
pcol = "orange",
position_names = c("Ljubljana",
"Ivancna Gorica",
"Dolenjske Toplice",
"Loski Potok"),
position_legend_title = "Obcina",
legend_position = "right",
aes_by_pos = TRUE,
add_text = TRUE,
ttype = "label",
tsize = 3,
t_hjust = -3000,
t_vjust = 1000)
#Look at one of the new frames
# r_frames_style_point[5]
#Alternatively add points
# points_mat <- SI_positions$points_matrix #Points in Slovenia
# r_frames_style_point_mat <- ts_add_positions_to_frames(r_frame_list = r_frames,
# positions = points_mat,
# psize = 4,
# pcol = "orange",
# position_names = c("A",
# "B" ),
# position_legend_title = "Point",
# legend_position = "right",
# aes_by_pos = TRUE,
# add_text = TRUE,
# ttype = "label",
# tsize = 3,
# t_hjust = -3000,
# t_vjust = 1000)
#Look at one of the new frames
# r_frames_style_point_mat[5]
# }
Run the code above in your browser using DataLab