Description Usage Arguments Functions Source Examples
View source: R/bivariate_plot.R
These functions can be used to combine two raster layers in a bivariate plot. To generate a
bivariate plot, first a matrix with the color codes and a raster layer that is a combination of
the two layers that should be plotted have to be calculated. The function rg_big_cmat
can be used
to generate the color matrix and the function rg_biv_create_raster
to combine the two single
raster files. The outputs of these two functions are then used in the function rg_biv_plot_raster
to create the final plot. The function rg_biv_get_legend
can optionally be used to inspect
the final legend and is used internally by the function rg_biv_plot_raster
to create the legend
for the plot.
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 | rg_biv_cmat(
breaks,
style = 1,
upper.left = NULL,
upper.right = NULL,
lower.left = NULL,
lower.right = NULL
)
rg_biv_get_legend(
cmat,
xlab = "",
ylab = "",
label.size = 12,
label.color = "black"
)
rg_biv_create_raster(x, y, breaks)
rg_biv_plot_raster(
bivraster,
cmat,
xlab = "",
ylab = "",
border = NULL,
crs = "+init=epsg:4326",
na.value = "transparent",
legend.height = 0.25,
legend.width = 0.25,
legend.x = 0.75,
legend.y = 0.2,
limits = NULL
)
|
breaks |
integer, number of breaks used to generate the bivariate color scale |
style |
integer, number between 1 and 9 to select different predefined color combinations |
upper.left |
string, upper left color |
upper.right |
string, upper right color |
lower.left |
string, lower left color |
lower.right |
string, lower right color |
cmat |
matrix, a matrix with hexcolor codes such as returned from the function |
xlab |
string, x-label of the legend |
ylab |
string, y-label of the legend |
label.size |
numeric, size of legend labels |
label.color |
string, color of legend label |
x |
raster layer, first layer for bivariate plot |
y |
raster layer, second layer for bivariate plot |
bivraster |
raster, the raster object returned from the function |
border |
sf object, optionally plot an sf object as border around raster. Make sure the sf object has the same crs as the bivraster |
crs |
string, specification of the coordinate system you want to plot the bivraster in. Per Default uses EPSG:4326 |
na.value |
string, color for NA values |
legend.height |
numeric, height of legend |
legend.width |
numeric, width of legend |
legend.x |
numeric, relative x position of legend |
limits |
optionally zoom in into plot using x and y limits. Use the syntax limits = c(xmin, xmax, ymin, ymax). |
legnend.y |
numeric, relative y position of legend |
rg_biv_cmat
: Generate color matrix
rg_biv_get_legend
: Generate legend from color matrix
rg_biv_create_raster
: Combine both single raster files to bivariate raster
rg_biv_plot_raster
: Create bivariate plot
#https://stackoverflow.com/questions/54144269/bivariate-choropleth-map-in-r
1 2 3 4 5 6 | breaks <- 3
cmat <- rg_biv_cmat(breaks, style = 1)
legend <- rg_biv_get_legend(cmat, xlab = 'Gain', ylab = 'Loss')
xy <- rg_biv_create_raster(x, y, breaks)
map <- rg_biv_plot_raster(xy, cmat, border = st_border_proj, xlab = 'Gain', ylab = 'Loss', limits = c(10.7, 12, 46.2, 46.8))
map
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.