I'm trying to get partially italicized facet headings in ggplot2
. I want the facets in a specific order, which I specify using facet_grid(~factor(YSD, levels = c('465', '466', '1572')
Here's a head
of my data
> head(df)
YSD Media OD Replicate
1 465 - Met 1.790500 1
2 465 - Met 1.616300 1
3 465 - Met 1.745700 1
4 465 - Met 2.439433 1
5 465 - Met 2.070033 1
6 465 - Met 2.192433 1
> dput(df[1:10,])
structure(list(
YSD = c("465", "465", "465", "465", "465", "465", "465", "465", "465",
"465"),
Media = c("- Met", "- Met", "- Met", "- Met", "- Met", "- Met", "30 µM
Met", "30 µM Met", "30 µM Met", "30 µM Met"),
OD = c(1.7905, 1.6163, 1.7457, 2.439433, 2.070033, 2.192433, 1.9288,
1.5506, 1.5966, 2.204833),
Replicate = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)),
row.names = c(NA, 10L),
class = "data.frame")
And here's my code:
df <- read.csv("37C all.txt", sep="\t", check.names=FALSE)
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
my_labels <- c(expression(paste(italic("C. glabrata"), "CBS138")),
expression(paste(italic("C. glabrata "), Delta, "HTL")),
expression(paste(italic("Met3p-Hsp90"))))
df$YSD <- as.character(df$YSD)
dplot <- ggplot(data = df, aes(x = Media, y = OD, fill = YSD)) +
geom_boxplot(outlier.colour = "white") +
geom_dotplot(binaxis='y', stackdir='center', dotsize=0.5, binwidth = NULL) +
facet_grid(~factor(YSD, levels = c('465', '466', '1572'), labels = my_labels)) +
scale_y_continuous(limits = c(0, 3.0)) +
scale_x_discrete(limits=c("- Met", "30 µM Met", "40 µM Met", "DMSO", "50 µM Radicicol")) +
theme(axis.text = element_text(size=12), axis.title = element_text(size=12)) +
theme_bw() +
theme(axis.text.x = element_text(angle = 80, vjust = 0.5)) +
theme(legend.position = "none") +
labs(title = "37°C Adhesion")
This gives me this plot:
I've tried setting the levels externally like here and here using:
levels(df$YSD) = c("465" = expression(paste(italic("C. glabrata"), "CBS138")),
"466" = expression(paste(italic("C. glabrata "), Delta, "HTL")),
"1572" = expression(paste(italic("Met3p-Hsp90"))))
but I get the error message:
Error in levels(df$YSD) = c(`465` = expression(paste(italic("C. glabrata"), :
unimplemented type 'expression' in 'HashTableSetup'
Any help would be hugely appreciated. Thank you.