The function is wrapper around ggplot2::geom_raster()
that plots from a data.frame with
columns for x and y coordinates along with an associated numeric attribute.
The function accepts a data frame with columns for numeric x/y values and an attribute that will be mapped as a color or fill aesthetic. Function provides additional ggplot2 text labeling and axis scaling.
create_raster_plot(
df,
aes_x = NULL,
aes_y = NULL,
aes_color = NULL,
aes_fill = NULL,
interpolate = FALSE,
title = NULL,
subtitle = NULL,
caption = NULL,
center_titles = FALSE,
x_title = NULL,
y_title = NULL,
hide_x_tics = FALSE,
hide_y_tics = FALSE,
panel_color = "white",
panel_border_color = "black",
x_limits = NULL,
x_major_breaks = waiver(),
x_minor_breaks = waiver(),
x_labels = waiver(),
y_limits = NULL,
y_major_breaks = waiver(),
y_minor_breaks = waiver(),
y_labels = waiver(),
scale_breaks = waiver(),
scale_values = NULL,
scale_limits = NULL,
scale_labels = waiver(),
scale_colors = heat.colors(8),
scale_na_value = "gray50",
own_scale = FALSE,
show_legend = TRUE,
legend_pos = "right",
legend_key_width = 0.5,
legend_key_height = 0.7,
legend_key_backgrd = "white"
)
A ggplot class object.
The required data.frame derived from a raster file (such as *.tiff) to be plotted.
The required name of aesthetic variable from 'df' for the x dimension.
The required name of aesthetic variable from 'df' for the y dimension.
The variable name from 'df' for the attribute dependent aesthetic mapping for color.
The variable name from 'df' for the attribute dependent aesthetic mapping for fill.
A logical which if TRUE interpolate linearly.
A string that sets the plot title.
A string that sets the plot subtitle.
A string that sets the plot caption
A logical which if TRUE
centers both the 'title' and 'subtitle'.
A string that sets the x axis title. If NULL (the default) then the x axis title does not appear.
A string that sets the y axis title. If NULL (the default) then the y axis title does not appear.
A logical that controls the appearance of the x axis tics.
A logical that controls the appearance of the y axis tics.
A string in hexidecimal or color name that sets the plot panel's color. The default is "white".
A string in hexidecimal or color name that sets the plot panel's border color. The default is "black".
Depending on the class of 'aes_x', a numeric/Date/POSIXct 2 element vector that sets the minimum
and maximum for the x axis. Use NA
to refer to the existing minimum and maximum.
Depending on the class of 'aes_x', a numeric/Date/POSIXct vector or function that defines the exact major tic locations along the x axis.
Depending on the class of 'aes_x', a numeric/Date/POSIXct vector or function that defines the exact minor tic locations along the x axis.
A character vector with the same length as 'x_major_breaks', that labels the major tics.
A numeric 2 element vector that sets the minimum and maximum for the y axis.
Use NA
to refer to the existing minimum and maximum.
A numeric vector or function that defines the exact major tic locations along the y axis.
A numeric vector or function that defines the exact minor tic locations along the y axis.
A character vector with the same length as 'y_major_breaks', that labels the major tics.
A string/numeric vector that defines the scale breaks.
A string/numeric vector that defines the possible values.
A string/numeric vector that defines the scale limits.
An optional string vector that defines the scale labels. Vector must be the same length
as scale_breaks
.
Vector of colors to use for n-color gradient.
A string that sets the color for missing values.
A logical which if TRUE
, then your own scaling may be appended to the plot without using the above
scale_* parameters.
A logical that controls the appearance of the legend.
A string that sets the legend position. Acceptable values are "top", "bottom", "left", "right".
A numeric that sets the legend width in cm.
A numeric that sets the legend height in cm.
A string that sets the legend's background color.
library(ggplot2)
library(RplotterPkg)
RplotterPkg::create_raster_plot(
df = RplotterPkg::kentucky_elevation,
title = "County Elevations in Southeast Kentucky",
aes_x = "x",
aes_y = "y",
aes_fill = "elevation"
) +
ggplot2::geom_sf(
data = RplotterPkg::kentucky_counties,
aes(x = NULL, y = NULL),
alpha = 0,
linewidth = 1.5
) +
ggplot2::geom_sf_text(
data = RplotterPkg::kentucky_counties,
aes(x = NULL, y = NULL, label = ID)
)
Run the code above in your browser using DataLab