I have a 2 x 2 experimental design where I am looking at the relationship between mean urchin abundance and coral recruitment. The study has 2 sites (Waikiki and Hanauma Bay) and 2 shelter treatments (Low and High). I want to make a legend in which these 4 unique combinations of Site x Shelter (Waikiki - Low, Waikiki - High, Hanauma Bay - Low, Hanauma Bay - High) are represented by two figure shapes corresponding to Site (Waikiki and Hanauma Bay) with the fill of these shapes indicating Shelter (Low and High).
When I do this by mapping shape to Site and fill to Shelter, I get the following figure with 2 separated legends for Site and Shelter. I want all 4 Site x Shelter combinations to be represented in the legend with the shape of the point to represent Site while the black or white fill represents Shelter.
Database
urchin_vs_recruitment_summary_data <- structure(list(Site_long = structure(c(2L, 2L, 1L, 1L), .Label = c("Hanauma Bay",
"Waikiki"), class = "factor"), Treatment_long = c("Closed", "Open",
"Closed", "Open"), Shelter = structure(c(1L, 2L, 1L, 2L), .Label = c("Low",
"High"), class = "factor"), recruitment_mean = c(4.16666666666667,
2.5, 0.833333333333333, 1.16666666666667), recruitment_sd = c(2.96741563579414,
2.21735578260835, 1.06718737290547, 1.51840559652405), recruitment_lower = c(3.31004755860504,
1.85990452101095, 0.525262874821961, 0.728340726720569), recruitment_upper = c(5.02328577472829,
3.14009547898905, 1.14140379184471, 1.60499260661276), urchin_mean = c(0.166666666666667,
0.375, 3.66666666666667, 22.75), urchin_sd = c(0.372677996249965,
0.414578098794425, 2.73353657780945, 17.3066701977398), urchin_lower = c(0.0590837959386828,
0.255321611530458, 2.87756262714768, 17.7539946512794), urchin_upper = c(0.27424953739465,
0.494678388469542, 4.45577070618566, 27.7460053487206)), row.names = c(NA,
-4L), vars = c("Site_long", "Treatment_long"), drop = TRUE, indices = list(
2L, 3L, 0L, 1L), group_sizes = c(1L, 1L, 1L, 1L), biggest_group_size = 1L, labels = structure(list(
Site_long = structure(c(1L, 1L, 2L, 2L), .Label = c("Hanauma Bay",
"Waikiki"), class = "factor"), Treatment_long = c("Closed",
"Open", "Closed", "Open")), row.names = c(NA, -4L), class = "data.frame", vars = c("Site_long",
"Treatment_long"), drop = TRUE), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"))
Figure
urchin_vs_recruitment_plot <- ggplot(data = urchin_vs_recruitment_summary_data, aes(x = urchin_mean, y = recruitment_mean, fill = Shelter, shape = Site_long)) +
ggtitle("Urchin Abundance vs Coral Recruitment") +
geom_point(aes(size = 3)) +
scale_shape_manual(values = c(21, 24)) +
coord_cartesian(ylim = c(0,5)) +
scale_fill_manual(values = c(NA, "black"), guide = guide_legend(override.aes = list(shape = 21))) +
guides(size = FALSE) +
theme(text = element_text(size = 15)) +
geom_errorbar(aes(ymin = recruitment_lower, ymax = recruitment_upper), width = .6) +
geom_errorbarh(aes(xmin = urchin_lower, xmax = urchin_upper), height = .15) +
labs(x = "Mean urchin abundance ± SEM", y = "Mean coral recruitment ± SEM") +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"), axis.title = element_text(size = rel(1.5)), axis.text = element_text(size = rel(1.5)), legend.text = element_text(size = rel(1.5)), plot.title = element_text(size = 20, hjust = 0.5, vjust = -1.5), legend.position = c(.8, .8))
As mentioned above, I want a figure with a single legend with 4 entries (Waikiki - Low, Waikiki - High, Hanauma Bay - Low, Hanauma Bay - High) with a non-filled or white triangle for Waikiki - Low, filled or black triangle for Waikiki - High, non-filled or white circle for Hanauma Bay - Low, and filled or black circle for Hanauma Bay - High.