simonthompson99
9/27/2019 - 4:22 PM

[ggplot Commands] Some ggplot commands #r #ggplot

[ggplot Commands] Some ggplot commands #r #ggplot

#-- stacked bar plot of proportions with totals above
# d is listing of single row per participants with eth_cat and quarter columns
# totals is d %>% group_by(quarter) %>% summarise(total = n())
ggplot(d, aes(fill = eth_cat, x = quarter)) +
    geom_bar(position = "fill") +
    scale_fill_brewer(palette = "RdYlBu") +
    labs(title = "Participant ethnicity per quarter of 100,000 Genomes Project",
         x = "Quarter",
         y = "Proportion",
         fill = "Ethnicity",
         caption = paste("Generated by Clinical Data Team (Simon Thompson) on", today())) +
    geom_text(data = totals,
          aes(quarter, 1, label = paste0("n=", total), fill = NULL, vjust = -0.5))
 
#-- expand an rcolorbrewer palette to more colours
new_palette <- colorRampPalette(brewer.pal(11, "RdYlBu")) # 11 is length of the palette, display.brewer.all() shows all palettes
ggplot(d, aes(x = date, y = count, fill = gmc) +
    geom_area() +
    scale_fill_manual(values = new_palette(length(unique(d$gmc))))