颜色条不均匀,R ggplot2比例\颜色\渐变
我试图用ggplot2创建一个绘图,但颜色栏并不代表实际数据。情节看起来不错 这是我的数据颜色条不均匀,R ggplot2比例\颜色\渐变,r,ggplot2,gradient,colorbar,R,Ggplot2,Gradient,Colorbar,我试图用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
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()
data$KEGG_路径具有对数刻度的彩色地图可能是您问题的可接受解决方案:
data <- structure(list(id = 1:10, KEGG_Pathway = structure(c(1L, 10L,
3L, 6L, 4L, 9L, 7L, 2L, 8L, 5L), .Label = c("Amino acid metabolism",
"Biosynthesis of other secondary metabolites", "Carbohydrate metabolism",
"Energy metabolism", "Lipid metabolism", "Metabolism of cofactors and vitamins",
"Metabolism of other amino acids", "Metabolism of terpenoids and polyketides",
"Nucleotide metabolism", "Xenobiotics biodegradation and metabolism"
), class = "factor"), Count = c(67L, 31L, 54L, 34L, 23L, 13L,
15L, 20L, 13L, 9L), Ratio = c(11.67, 11.07, 7.78, 8.76, 9.58,
8.39, 7.94, 5.17, 3.27, 2.77), pval_adjusted = c(1.231153e-14,
4.492243e-06, 2.940591e-05, 0.0002439616, 0.001488961, 0.1285896,
0.1255625, 1, 1, 1)), .Names = c("id", "KEGG_Pathway", "Count",
"Ratio", "pval_adjusted"), class = "data.frame", row.names = c(NA,
-10L))
library(ggplot2)
library(RColorBrewer)
data$KEGG_Pathway <- factor(data$KEGG_Pathway, levels = rev(data$KEGG_Pathway))
myPalette <- colorRampPalette(c("red","blue","green"))(15)
ggplot(data, aes(Count, KEGG_Pathway)) + geom_point(aes(color=pval_adjusted, size=Ratio)) +
scale_colour_gradientn(colours = myPalette, trans="log",
breaks = 10^(-c(0:14)), limits = c(10e-15,1)) +
scale_size_area(breaks = seq(0,12, by=2)) + theme_bw()
数据谢谢!这管用!次要细节,用于色盲安全方案:myPalette