0

数据框有许多连续的数字列(例如gr)和一个样本标识符 - wellseq。每个 都有很多行数据wellseqwellseq在一个数据框中 - 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

..count.. 在条形图中创建离散边界。 填充为单色 我试图得到一个像附加的情节。请指导。提前致谢。

期望的输出

4

1 回答 1

0

如果你设置aes(x=gr, fill=wellseq)了,那么你应该得到你正在寻找的东西,它是 gr 的子集的分组,由它们在 wellseq 中的成员资格定义。

看这里。具有多个群体的分组直方图R 直方图的先前简单版本

于 2016-08-01T16:49:24.127 回答