add_arrows: Add arrows to bivariate histograms

Description Usage Arguments Value Examples

View source: R/add_arrows.R

Description

Show change in bins from one histogram to another

Usage

1
add_arrows(histogram.primary, histogram.base)

Arguments

histogram.primary

the histogram that arrows will be plotted on

histogram.base

the histogram from which arrows will be calculated

Value

histogram.primary

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
library(stars)
library(Vizumap)
library(gridExtra)
palette = build_palette(name = "BlueRed")
# matched time to decadal time periods and produce histograms
time <- as.numeric(st_get_dimension_values(tmax, 2))
periods <- list(c(1950:1959), c(1960:1969), c(1970:1979), c(1980:1989),c(1990:1999))
decades <- lapply(periods, function(x, time) which(time %in% x), time)

# Find bounds on whole data set
out = st_assign_colors(tmax, 1, tmin, 1, FALSE, palette = palette)
bounds = out$bounds

# Preparing the data
out2 <- st_assign_colors(tmax[,,decades[[5]]], 1, tmin[,,decades[[5]]], 1, terciles = FALSE,
palette = palette, bounds = bounds)
data2 <- out2$data
out1 <- st_assign_colors(tmax[,,decades[[1]]], 1, tmin[,,decades[[1]]], 1, terciles = FALSE,
palette = palette, bounds = bounds)
data1 <- out1$data


# generating and plotting the histogram
bvh1 <- st_bivariate_histogram(data = data1,
            title = "Max/Min temperature distribution (1950-1959)", ymax = 1)
bvh1

bvh2 <- st_bivariate_histogram(data = data2,
           title = "Max/Min temperature distribution (1990-1999)", ymax = 1)
bvh2

colnames(data1) = c("Tmax","Tmin","bothVars","hex_code")
colnames(data2) = c("Tmax","Tmin","bothVars","hex_code")
key <- build_bkey(data1, palette, terciles = FALSE)
key = st_change_key_bounds(key, bounds)

# add arrows
bvh2 = add_arrows(histogram.primary = bvh2, histogram.base = bvh1)

# attach key
densityviz::attach_key(arrangeGrob(bvh1, bvh2, ncol = 1), key)

JamesMCollier/densityviz documentation built on Dec. 18, 2021, 12:31 a.m.