【发布时间】:2018-04-04 03:18:13
【问题描述】:
> 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"))
这是我现在的图表:
但这是我希望图表的样子:
我愿意
1) 翻转我的图表,使条形图是水平的(我试过 coord_flip,但没用)
2) 对并排的条进行不同的颜色编码(例如,“人口”的不同颜色,当然还有相应的一组图例(总共 4 个图例)
3) 摆脱“ATM”和“人口”标签
【问题讨论】:
-
@Nate 是的,我试过了。它没有工作
-
抱歉没有看完你的评论,所以我删除了,现在换个角度工作
-
试试
+ facet_wrap(~ Cancer, ncol = 1) + coord_flip()而不是facet_grid(~ Cancer)。