【发布时间】:2018-01-01 22:01:12
【问题描述】:
我正在尝试使用 ggplot2 创建绘图,但颜色条不代表实际数据。剧情看起来不错。
这是我的数据
KEGG_Pathway Count Ratio pval_adjusted
1 Amino acid metabolism 67 11.67 1.231153e-14
2 Xenobiotics biodegradation and metabolism 31 11.07 4.492243e-06
3 Carbohydrate metabolism 54 7.78 2.940591e-05
4 Metabolism of cofactors and vitamins 34 8.76 2.439616e-04
5 Energy metabolism 23 9.58 1.488961e-03
6 Nucleotide metabolism 13 8.39 1.285896e-01
7 Metabolism of other amino acids 15 7.94 1.255625e-01
8 Biosynthesis of other secondary metabolites 20 5.17 1.000000e+00
9 Metabolism of terpenoids and polyketides 13 3.27 1.000000e+00
10 Lipid metabolism 9 2.77 1.000000e+00
还有代码:
data$KEGG_Pathway <- factor(data$KEGG_Pathway, levels = rev(data$KEGG_Pathway))
myPalette <- colorRampPalette(brewer.pal(9, "BrBG"))(7)
ggplot(data, aes(Count, KEGG_Pathway)) + geom_point(aes(color=pval_adjusted, size=Ratio)) +
scale_colour_gradientn(colours = myPalette,
values = rescale(c(1.23e-14,4.49e-06,2.94e-05,2.44e-04,
1.49e-03,1.29e-01,1.26e-01,1)), limits = c(1e-14,1)) +
scale_size_area(breaks = seq(0,12, by=2)) + theme_bw()
情节看起来和我想要的完全一样。但是颜色条完全是疯狂的(我想要一个渐变条来显示我的向量值的限制,以及我调色板中的所有颜色,就像在here 中一样):
我玩过 guide = "colorbar" 和 guide_colorbar() ,但它总是会产生这种效果。
【问题讨论】:
标签: r ggplot2 gradient colorbar