ggplot2 - Stacked Histogram in R ggplot with 100+ qualitative colors -


the data frame has many continuous numeric columns (e.g. gr) , sample identifier - wellseq. there many rows of data each wellseq. in data frame - there 94 distinct levels of wellseq in 10227 rows. header lines data frame are:

 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 

summary of column gr below:

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 

basic histogram of entire data gr suitably created. further analysis, required identify each wellseq contributing in histogram. ggplot() script used is:

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") 

sequential color in histogram resulting output has color - "sequential" , not "qualitative" palette "dark2". tried using answer in "how generate number of distinctive colors in r?" @ stackoverflow.com , created required colors.

dcolor = grdevices::colors()[grep('gr(a|e)y', grdevices::colors(), invert = t)] dcolorr <- sample(dcolor, 433, replace = f) 

using scale_colour_manual(values = dcolorr)

gives same histogram. using ..count.. y histogram show boundaries different wellseq not fill needed.

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 blue colored staked histogram 

..count.. creates discrete boundaries in bars. fill single color trying plot attached. please guide. in advance.

desired output

if set aes(x=gr, fill=wellseq) should looking grouping of subsets of gr defined membership in wellseq.

look here.previous simple version of grouped histogram r histogram multiple populations


Comments