Description Usage Arguments Value Examples
Show change in bins from one histogram to another
1 | add_arrows(histogram.primary, histogram.base)
|
histogram.primary |
the histogram that arrows will be plotted on |
histogram.base |
the histogram from which arrows will be calculated |
histogram.primary
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.