> dput(gene_cancer2_f)
structure(list(Gender = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Female", "Male"
), class = "factor"), Gene = c("ATM", "ATM", "ATM", "ATM", "Population",
"Population", "Population", "Population", "ATM", "ATM", "ATM",
"ATM", "Population", "Population", "Population", "Population"
), Cancer = structure(c(2L, 3L, 5L, 12L, 2L, 3L, 5L, 12L, 2L,
3L, 5L, 12L, 2L, 3L, 5L, 12L), .Label = c("Brain", "Breast",
"Colorectal", "Endometrial", "Gastric", "Hepatobiliary", "Kidney",
"Leukemia", "Melanoma", "Osteosarcoma", "Ovarian", "Pancreatic",
"Prostate", "Soft Tissue Sarcoma", "Thyroid", "Urinary Bladder"
), class = "factor"), Type = c("RiskToAge70", "RiskToAge70",
"RiskToAge70", "RiskToAge70", "RiskToAge70", "RiskToAge70", "RiskToAge70",
"RiskToAge70", "RiskToAge85", "RiskToAge85", "RiskToAge85", "RiskToAge85",
"RiskToAge85", "RiskToAge85", "RiskToAge85", "RiskToAge85"),
Risk = c(21.59862, 3.27479, 1.10073, 1.70754, 8.85253, 1.66318,
0.23228, 0.44844, 39.61044, 7.07614, 2.50735, 4.46698, 13.66465,
3.59502, 0.52923, 1.17365)), row.names = c(NA, -16L), .Names = c("Gender",
"Gene", "Cancer", "Type", "Risk"), class = "data.frame")
ggplot(gene_cancer2_f, aes(x = Gene, y = Risk, fill = Type)) +
geom_bar(stat = 'identity', position = 'stack') +
facet_grid(~ Cancer) +
scale_y_continuous(limits = c(0, 100)) +
labs(x = "Cancer", y = "Risk %") +
guides(fill = guide_legend(title = NULL)) +
theme_minimal() +
theme(plot.title = element_text(size = 12, hjust = 0.5),
legend.position = "bottom") +
scale_fill_manual(values = c("dodgerblue4", "sandybrown"),
breaks=c("RiskToAge70", "RiskToAge85"),
labels=c(paste("Risk to Age 70", " "), "Risk to Age 85"))
This is the graph I have right now:
But this is what I want the graphs to look like:
I'd like to
1) flip my graph so that the bars are horizontal (I've tried coord_flip, but that didn't work)
2) color-code the side-by-side bars differently (e.g. a different color for "Population,", and of course, the corresponding set of legends (so 4 legends total)
3) get rid of the "ATM" and "Population" labels