Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/ts_add_positions_to_frames.R
Add points, coordinates, or polygons to a list of spatial plots
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ts_add_positions_to_frames(
r_frame_list,
positions,
position_names = NULL,
pcol = "red",
tcol = "red",
psize = 2,
tsize = 7,
ttype = "text",
t_hjust = 0,
t_vjust = 0,
position_legend_title = "Position",
legend_position = "right",
aes_by_pos = FALSE,
col_by_pos = FALSE,
add_text = FALSE
)
|
r_frame_list |
list of ggplots, as generated by |
positions |
object containing the coordinates. One of
|
position_names |
(Optional) character, names of the positions to be added in legend or text (If |
pcol |
(Optional) character, color of the spatial objects. Default is |
tcol |
(Optional) character, if |
psize |
(Optional) numeric, plot size of the spatial objects. Default is |
tsize |
(Optional) numeric, if |
ttype |
(Optional) character, if |
t_hjust |
(Optional) numeric, if |
t_vjust |
(Optional) numeric, if |
position_legend_title |
(Optional) character, title of the legend. Default is |
legend_position |
(Optional) character, position of the legend. Use |
aes_by_pos |
(Optional) logical. If |
col_by_pos |
(Optional) logical. If |
add_text |
(Optional) logical. If |
The function takes a positions
object, which can be a spatial object or a matrix of coordinates, and adds them to each of the elements of r_frame_list
. Optionally it also adds text at their respective positions usingadd_text.
- ts_add_positions_to_frames
is intended to be an easy way to add multiple objects to the spatial frames at fixed positions.
For adding individual positions or text, potentially at varying positions, it is recommended to all add_gg and add_text directly.
A list of ggplots with added positions.
Johannes Mast
add_text add_gg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #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]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.