I'm creating an overlapping bar graph with the code below:
library(ggplot2)
library(reshape)
library(scales)
x = data.frame('DB' = c('Table4annot', 'UCSC_old', 'UCSC_new'), 'all_elements' = c(595632, 605914, 711073), 'unique_loci' = c(264978, 265979, 274936), 'start_codons' = c(10661, 10714, 22815))
melted = melt(x, id="DB")
p = ggplot(melted, aes(x = DB, y = value, fill = variable))
p = p + geom_bar(stat = "identity", position = "identity", alpha = 0.7, color = 'black', size = 0.4)
p = p + geom_label(aes(label = comma(value), fill = variable), vjust = -0.2, size = 3, show.legend = FALSE, label.padding = unit(0.2, 'lines'))
p = p + scale_x_discrete(limits = c('Table4annot', 'UCSC_old', 'UCSC_new'), labels=c("Table4annot", "UCSC our archive", "UCSC current"))
p = p + scale_y_continuous(labels = comma, expand = c(0, 0), limits = c(0, 750000), breaks = seq(0, 700000, 100000))
p = p + theme(panel.border = element_rect(colour = 'black', fill = NA),
panel.background = element_rect(fill = "white"),
panel.grid.major.y = element_line(colour = "grey40", size = 0.3),
panel.grid.minor.y = element_line(colour = "grey40", size = 0.1),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.title = element_blank(),
axis.ticks.x = element_blank(),
legend.title = element_blank(),
legend.position = 'top')
p = p + scale_fill_manual(labels = c('All annotated elements', 'Unique loci with annotation', 'Number of annotated start codons'), values = c(rgb(86, 180, 233, maxColorValue = 255, alpha = 1), rgb(240, 228, 66, maxColorValue = 255, alpha = 1), rgb(0, 0, 0, maxColorValue = 255, alpha = 1)))
p
Since I'm using geom_label(), I get these nice boxed labels filled with the color of the respective bar. But when using scale_fill_manual(), which I do because I didn't find a better way to customise the colours, the boxed labels get a white background. Anybody an idea why?
Any help would be greatly appreciated! Thanks :)
My sessionInfo() is a bit long, but if it's necessary I can add it later. Don't think it matters in this scenario.