plot_patches: plot_patches

Description Usage Arguments Examples

View source: R/plot_patches.R

Description

Plot hot and cold patches returned from get_patches.

Usage

 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
plot_patches(
  df,
  patches,
  bg_poly = NULL,
  bg_colour = "grey",
  facet_cols = NULL,
  facet_rows = NULL,
  plot_distribution = TRUE,
  print_plot = TRUE,
  save_plot = FALSE,
  return_plot = FALSE,
  out_dir = NULL,
  file_name = NULL,
  file_ext = "png",
  fig_width = 8,
  fig_height = 9,
  fig_units = "cm",
  lab_size = 8,
  text_size = 6,
  outline_size = 0.7,
  val_pal = c("black", "#050155", "#120172", "#3b008e", "#7200a9", "#8f00a0",
    "#ba187f", "#d9365b", "#ed5930", "#f76323", "#fa8600", "#f6a704", "#fad61e",
    "#fad61e"),
  hatching = FALSE,
  hatch_density = c(1, 2),
  hatch_angle = c(45, 135),
  hatch_size = 0.5,
  fill_breaks = waiver(),
  patch_cols = c("mistyrose", "cornflowerblue"),
  patch_labs = c("Hot spots", "Cold spots"),
  val_lab = NULL
)

Arguments

df

A dataframe returned from get_patches.

patches

A SpatialPolygonsDataFrame returned from get_patches.

bg_poly

An optional background polygon. Can be a SpatialPolygonsDataFrame or fortified dataframe (see ggplot2::fortify) with the variables 'long', 'lat' and 'group'.

bg_colour

Colour of the background polygon.

facet_cols

Number of facet columns. Defaults to NULL.

facet_rows

Number of facet rows. Defaults to NULL.

plot_distribution

Should a histogram be plotted? Defaults to TRUE.

print_plot

Should the resulting plots be printed? Defaults to FALSE.

save_plot

Should the resulting plots be saved? Defaults to TRUE.

return_plot

Should the resulting plots be returned? Defaults to FALSE.

out_dir

Path to directory where plots should be saved (if applicable).

file_name

Prefix for plot filenames (if applicable). If none specified, uses generic names 'distribution' and 'patches'.

file_ext

File extension. Defaults to '.png'.

fig_width

Figure width (if saved). Defaults to 8.

fig_height

Figure height (if saved). Defaults to 9.

fig_units

Figure dimension units (if saved). Defaults to "cm".

lab_size

Size of axis labels. Defaults to 8.

text_size

Size of axis text and legend text. Defaults to 6.

outline_size

Size of the outline. Defaults to 0.7.

val_pal

Colour palette to use for raster. Defaults to palette derived from a FLIR jpeg: c("black", "#050155", "#120172", "#3b008e", "#7200a9", "#8f00a0","#ba187f", "#d9365b", "#ed5930","#f76323", "#fa8600", "#f6a704","#fad61e", "#fad61e").

hatching

Option to add hatching to patch polygons. Defaults to FALSE

hatch_density

Option to specify density of hatching (hot spot value followed by cold spot value). Defaults to: c(1, 2).

hatch_angle

Option to specify angle of hatching (hot spot value followed by cold spot value). Defaults to: c(45, 135).

hatch_size

Line thickness of hatching. Defaults to 0.5

fill_breaks

Option to manually specify breaks in colourbar. Defaults to waiver(), where breaks are computed by the transformation object (see ggplot2::scale_colour_gradient).

patch_cols

Colours for the patch borders (hot spot colour followed by cold spot colour). Defaults to: c("mistyrose", "cornflowerblue").

patch_labs

Labels to use in patch outline legend. Defaults to 'Hot spots' and 'Cold spots'.

val_lab

Label to describe the variable of interest - corresponds to the x axis of the histogram, and the fill legend of the raster plot.

Examples

 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
# FLIR temperature matrix ---------------------------------------------------
# Find hot and cold patches
flir_results <-
    get_patches(img = flir11835$flir_matrix,
                id = flir11835$photo_no)

# Look at the results for individual pixels
head(flir_results$df)

# Look at the patch statistics for hot and cold patches
flir_results$pstats

# Plot the patches
sp::plot(flir_results$patches)

# Plot using ThermStats::plot_patches with hatching
plot_patches(df = flir_results$df,
             patches = flir_results$patches,
             hatching = TRUE,
             print_plot = TRUE,
             save_plot = FALSE)
             
# Plot using ThermStats::plot_patches without hatching
plot_patches(df = flir_results$df,
             patches = flir_results$patches,
             hatching = FALSE,
             print_plot = TRUE,
             save_plot = FALSE)
             
 ## Not run: 
 # FLIR facets --------------------------------------------------------------
 # Load raw data
 raw_dat <- flir_raw$raw_dat
 camera_params <- flir_raw$camera_params
 metadata <- flir_metadata

 # Batch convert
 img_list <- batch_convert(raw_dat, write_results = FALSE)
 
 # Get patches
 patch_stats <-
     stats_by_group(img_list = img_list,
                    metadata = metadata,
                    idvar = "photo_no",
                    style = "C",
                    grouping_var = "rep_id",
                    round_val = 0.5,
                    sum_stats = c("mean", "max", "min"))
 
 # Plot
 plot_patches(df = patch_stats$df,
              patches = patch_stats$patches,
              print_plot = TRUE,
              save_plot = FALSE)  

# Worldclim2 temperature raster ---------------------------------------------
# Dataset 'sulawesi_temp' represents mean January temperature for the
# island of Sulawesi

# Define projection and extent
img_proj <- raster::projection(sulawesi_temp)
img_extent <- raster::extent(sulawesi_temp)

# Find hot and cold patches
worldclim_results <-
 get_patches(img = sulawesi_temp,
             id = "sulawesi",
             style = "C",
             img_proj = img_proj,
             img_extent = img_extent)

# Look at the results for individual pixels
head(worldclim_results$df)

# Look at the patch statistics for hot and cold patches
worldclim_results$pstats

# Plot the patches
sp::plot(worldclim_results$patches)

# Plot using ThermStats::plot_patches
plot_patches(df = worldclim_results$df,
             patches = worldclim_results$patches,
             bg_poly = sulawesi_bg,
             bg_colour = "grey",
             print_plot = TRUE,
             save_plot = FALSE)

## End(Not run)

rasenior/PatchStatsFLIR documentation built on Oct. 28, 2020, 11:53 p.m.