数据框有许多连续的数字列(例如gr
)和一个样本标识符 - wellseq
。每个 都有很多行数据wellseq
。wellseq
在一个数据框中 - 10227 行中有 94 个不同的级别。数据框中的标题行是:
gr wellseq
1 27.7049 1
2 31.1149 1
3 34.5249 1
4 39.7249 1
5 44.9249 1
6 50.1299 1
栏目摘要gr
如下:
summary(GR)
gr
Min. :-6.94
1st Qu.:10.71
Median :13.76
Mean :18.99
3rd Qu.:20.70
Max. :98.42
NA's :55
gr
适当地创建了整个数据的基本直方图。为了进一步分析,需要识别wellseq
直方图中的每个贡献。使用的ggplot()
脚本是:
p2 <- ggplot() + theme_bw() +
geom_histogram(data=GR, na.rm= TRUE, mapping = aes(x=gr, fill=factor(GR$wellseq)),
bins = 10) + scale_color_brewer(palette = "Dark2") +
scale_x_continuous(limits = c(-10, 100)) +
labs(title=paste("Gamma Ray","Histogram", sep=" ")) +
theme(legend.position = "none")
生成的输出具有颜色 - 这是“顺序”而不是“定性”调色板“Dark2”。我尝试使用“如何在 R 中生成许多最独特的颜色?”中的答案。@ stackoverflow.com 并创建了所需的颜色。
Dcolor = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = T)]
DcolorR <- sample(Dcolor, 433, replace = F)
使用scale_colour_manual(values = DcolorR)
给出相同的直方图。..count..
用于y
直方图确实显示了不同的边界,wellseq
但不会根据需要填充。
p3 <- ggplot() + theme_bw() +
geom_histogram(data=GR, na.rm= TRUE, mapping = aes(x=gr, y= ..count.., col = factor(GR$wellseq), bins = 10)) +
scale_colour_manual(values = DcolorR) +
scale_x_continuous(limits = c(-10, 100)) +
labs(title=paste("Gamma Ray"," Frequency Histogram", sep=" ")) +
theme(legend.position = "none")
fill = 1 # leads to blue colored staked histogram