Hello all,
I am trying to make a stacked bar plot with colors for different invertebrate taxa using ggplot2. Some of the critters were IDed to genus or species, whereas others were lumped into higher classifications. Therefore, some of the labels should be in italics, and some shouldn't. I've tried to use the "legend.text" element in the "theme" function, but it only seems to be able to change the font of the entire legend, not specific elements in it. I'd like a plot similar to what I've copied below, but with only the first five labels in italics. I've copied my code and attached some fake data as an example.
Any hints?
library(ggplot2)
#set up a figure with before/after on the s axis, CPUE on the y axis, colored by taxon
fig1 = ggplot(bugs3, aes(x=BA, y=CPUE, fill = tax))
# Make it faceted by control/treatment and location
fig1+ facet_grid(CT~Location) +
# it's a bar plot
geom_bar(stat = "identity", position = "stack") +
# fix the axis labels
xlab("Before/After") + ylab("Relative Abundace")+
#fix the fill labels. Can I make them italics at the same time? Not sure.
scale_fill_manual(name = "Taxon", labels = c("Gammarus sp.", "Crangonyx sp.", "Hyalella sp.", "Camptocerus sp.", "Daphnia sp.", "Calanoida", "Cyclopoida", "Ostracoda", "Chironoid larvae", "Other")) +
#try for italics. It only reads the first "face" statement.
theme(legend.text = element_text(face = c(rep("italic", 5), rep("plain", 5))))