Last active
June 18, 2023 02:58
-
-
Save benmarwick/82a4f22c613d78c7cb865ff4f17e3ab0 to your computer and use it in GitHub Desktop.
Geometric Index of Unifacial Retouch Zone visualisation with ggplot2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
# coords for vertices of polygons that make the zones | |
polydata <- rbind( | |
data.frame(x = c(0, 0.01, 0.99, 1), | |
y = c(0, 0.25, 0.25, 0), | |
group = "zone 1", | |
fill = "grey80", xc = .5, yc = 0.125), | |
data.frame(x = c(0, 0.025, 0.495, 0.495), | |
y = c(-0.01, -0.25, -0.25, -0.01), | |
group = "zone 2", | |
fill = "grey80", xc = .3, yc = -.12), | |
data.frame(x = c(0.025, 0.055, 0.495, 0.495), | |
y = c(-0.26, -0.5, -0.5, -0.26), | |
group = "zone 3", | |
fill = "grey80", xc = .3, yc = -.37), | |
data.frame(x = c(0.055, 0.085, 0.495, 0.495), | |
y = c(-0.51, -0.75, -0.75, -0.51), | |
group = "zone 4", | |
fill = "grey80", xc = .3, yc = -.61), | |
data.frame(x = c(0.505, 0.505, 0.975, 1), | |
y = c(-0.01, -0.25, -0.25, -0.01), | |
group = "zone 5", | |
fill = "grey80", xc = .71, yc = -.12), | |
data.frame(x = c(0.505, 0.505, 0.955, 0.975), | |
y = c(-0.26, -0.5, -0.5, -0.26), | |
group = "zone 6", | |
fill = "grey80", xc = .71, yc = -.37), | |
data.frame(x = c(0.505, 0.505, 0.925, 0.955), | |
y = c(-0.51, -0.75, -0.75, -0.51), | |
group = "zone 7", | |
fill = "grey80", xc = .71, yc = -.61), | |
data.frame(x = c(0.085, 0.255, 0.755, 0.925), | |
y = c(-0.76, -1, -1, -0.76), | |
group = "zone 8", | |
fill = "grey80", xc = .5, yc = -0.875) | |
) | |
# simulate some values to fill the zones | |
artefact_data <- | |
data.frame(zone = 1:8, | |
GIUR = runif(8)) | |
# join artefact data with polygons for plotting | |
library(tidyverse) | |
polydata <- | |
polydata %>% | |
mutate(zone = parse_number(group)) %>% | |
left_join(artefact_data) | |
# plot the values on the zone map | |
# avoid overprinting of labels | |
annotations <- | |
polydata %>% | |
distinct(group, xc, yc) | |
# draw the plot | |
ggplot(polydata, | |
aes( | |
x = x, | |
y = y, | |
group = group, | |
fill = GIUR, | |
colour = fill | |
)) + | |
geom_polygon(alpha = .5) + | |
scale_colour_identity() + | |
scale_fill_viridis_c(option = "D") + | |
annotate( | |
'text', | |
x = annotations$xc, | |
y = annotations$yc, | |
label = annotations$group, | |
size = 5 | |
) + | |
ggtitle("GIUR zones with ggplot2") + | |
coord_equal() + | |
theme_void() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.