I have the following data:
df4 <- structure(list(Domain = c("Archaea", "Archaea", "Archaea", "Archaea",
"Archaea", "Bacteria", "Bacteria", "Bacteria", "Bacteria", "Bacteria",
"Bacteria", "Bacteria", "Bacteria", "Eukaryota", "Eukaryota",
"Eukaryota"), Phylum = c("Crenarchaeota", "Euryarchaeota", "Korarchaeota",
"Nanoarchaeota", "Thaumarchaeota", "Acidobacteria", "Aquificae",
"Candidatus Poribacteria", "Chlamydiae", "Chlorobi", "Chloroflexi",
"Chrysiogenetes", "Cyanobacteria", "Apicomplexa", "Arthropoda",
"Ascomycota"), Alignment_Length = c(3573, 34060, 257, 22, 525,
85973, 8825, 1273, 5962, 41954, 169450, 1783, 117562, 1514, 5848,
12221), ymax = c(3573, 37633, 37890, 37912, 38437, 124410, 133235,
134508, 140470, 182424, 351874, 353657, 471219, 472733, 478581,
490802), ymin = c(0, 3573, 37633, 37890, 37912, 38437, 124410,
133235, 134508, 140470, 182424, 351874, 353657, 471219, 472733,
478581)), row.names = c(NA, -16L), class = c("tbl_df", "tbl",
"data.frame"))
I made the following 2-tiered pie chart:
ggplot(df4) +
geom_rect(aes(fill=Phylum, ymax=ymax, ymin=ymin, xmax=4, xmin=2)) +
geom_rect(aes(fill=Domain, ymax=ymax, ymin=ymin, xmax=2, xmin=0)) +
xlim(c(0, 4)) +
theme(aspect.ratio=1) +
coord_polar(theta="y") +
theme_void()
The inner tier represents domain and the outer tier represents phylum. The legend treats them both the same, though - it lumps all of the domains and phyla together. I would like to have two side-by-side legends with one for domain and one for phylum. Both legends should have their own title (i.e., either "Domain" or "Phylum"). Is it possible to do this? Thank you for your help.