# NOT RUN {
ggplot(
data.frame(x = 1:5, y = 1, size = 1:5, ratio = 1:5 * 0.2),
aes(x = x, y = y, size = size, ratio = ratio)
) +
geom_moon()
# To make full moon charts, you need two calls to geom_moon(), one with
# right = TRUE and one with right = FALSE and ratio equal to 1 - ratio
# from the first one
ggplot(dmeladh) +
geom_moon(
x = 0.5, y = 0.5, fill = "forestgreen", color = "forestgreen",
aes(ratio = AdhF / 100)
) +
geom_moon(
x = 0.5, y = 0.5, fill = "gold", color = "gold",
aes(ratio = AdhS / 100), right = FALSE
) +
facet_wrap(~Locality, ncol = 7)
# The same thing can be accomplished with a single call to geom_moon()
# using a "long" data frame with both frequencies if you set a grouping
# variable and set the `right` variable to a boolean column
dmeladh_long <- reshape(
dmeladh,
varying = c("AdhF", "AdhS"),
v.names = "freq",
timevar = "allele",
times = c("AdhF", "AdhS"),
idvar = c("Locality", "Latitude", "Longitude", "N"),
direction = "long"
)
dmeladh_long$right <- rep(c(TRUE, FALSE), each = nrow(dmeladh))
ggplot(dmeladh_long) +
geom_moon(
x = 0.5, y = 0.5, key_glyph = draw_key_rect,
aes(ratio = freq / 100, fill = allele, color = allele, right = right),
) +
facet_wrap(~Locality, ncol = 7)
# Moon charts (and pie charts) are sometimes useful on maps when x and y
# cannot be used as aesthetic dimensions because they are already spatial
# dimensions. Overplotting needs to be considered carefully, however.
ggplot(
subset(dmeladh, N > 200),
aes(Longitude, Latitude)
) +
geom_moon(aes(ratio = AdhF / 100), fill = "black") +
geom_moon(aes(ratio = AdhS / 100), right = FALSE) +
coord_fixed()
# }
Run the code above in your browser using DataLab