View source: R/plotting_functions.R
plot_structure_map | R Documentation |
Plots the mean cluster assignment for each population on a map using the
scatterpie
package alongside any additional simple feature objects
(see sf
from the sf
package). Assignments must be given in the
format provided by plot_structure
. This function is a wrapper
which sources code from github.
plot_structure_map(
assignments,
k,
facet,
pop_coordinates,
layers = NULL,
pop_names = T,
viridis.option = "viridis",
alt.palette = NULL,
radius_scale = 0.05,
label_args = NULL,
crop = FALSE,
scale_bar = list(),
compass = list(style = ggspatial::north_arrow_fancy_orienteering, location = "br"),
ask = TRUE
)
assignments |
Structure like results, parsed in or generated via
|
k |
numeric. Value of K (number of clusters) to plot. |
facet |
character. The facet by which data is broken down in the passed assignments. |
pop_coordinates |
sf object, see the documentation for |
layers |
list of |
pop_names |
logical, default T. If true, facet level names will be displayed on the map. |
viridis.option |
character, default "viridis". Viridis color scale
option. See |
alt.palette |
character or NULL, default NULL. Optional palette of colors to use instead of viridis palette the pie charts. |
radius_scale |
numeric 0-1, default 0.05. Scale for pie chart radii as a proportion of the total map space. |
label_args |
list, default NULL. Named list of arguments passed to
|
crop |
logical, default F. If TRUE, will will crop the plot around the sample points. If false will show the full extent of the data, often set by any additional sf objects being plotted. |
scale_bar |
list or NULL, default |
compass |
list or NULL, default |
ask |
logical, default TRUE. Should the function ask for confirmation before sourcing github code? |
Currently, this only works for simple, sample specific facets. Coordinates
for pie charts should be provided as an sf
object, where
one column, named for the facet being plotted, provides the subfacet level
names matching those in the assignments. Additional sf objects can be
provided, which will also be plotted. Note that there is no need to
standardize the CRS across the objects, since each will be transformed to
match the sample coordinates.
## Not run:
# get an sf of the sampling locations
lat_long <- data.frame(SMR = c(44.365931, -121.140420),
CLF = c(44.267718, -121.255805),
OPL = c(44.485958, -121.298360),
ASP = c(43.891693, -121.448360),
UPD = c(43.891755, -121.451600),
PAL = c(43.714114, -121.272797)) # coords for points
lat_long <- t(lat_long)
colnames(lat_long) <- c("lat", "long")
lat_long <- as.data.frame(lat_long)
lat_long$pop <- rownames(lat_long)
psf <- sf::st_as_sf(as.data.frame(lat_long), coords = c("long", "lat"))
psf <- sf::`st_crs<-`(psf, "EPSG:4326")
# get the assignments (STRUCTURE-like results)
assignments <- plot_structure(stickSNPs, "pop", alpha = 1)
# get a map of oregon as a background from the maps package.
background <- rnaturalearth::ne_states(iso_a2 = "US", returnclass = "sp")
background <- sf::st_as_sf(background)
background <- background[background$name %in% "Oregon",]
# make the plot
plot_structure_map(assignments, k = 2, facet = "pop", pop_coordinates = psf,
layers = list(ggplot2::geom_sf(data = background,
ggplot2::aes(fill = "example")),
ggnewscale::new_scale_fill()), radius_scale = .2)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.