r - How to produced group barplot with different color codes? -
i trying make grouped barplots below formatted data. wrote below code not serving purpose
data
data1 <- read.table(text=" nas ag pt st 1kb_+/-tss 1239 885 1232 952 1.5kb_+/-tss 1440 1092 1467 1181 2kb_+/-tss 1647 1248 1635 1398 2.5kb_+/-tss 1839 1403 1794 1594", header=true)
code
data2=as.matrix(data1) b<-barplot(data2, legend= rownames(data2), beside= true,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,3000), col=c("cornflowerblue","cornsilk4","red","orange")) tx2 <- data2 text(b,tx2+10, as.character(tx2),pos = 3, cex = 0.5, col = "darkgreen")
i not want have color combination want color each group nas(shades of blue each rows),ag(shades of cornsilk4, pt(shades of read), st(shades of orange)
how shall modify code? each category has lighter shades of 4 colours used in main code
if want different shades each of colors, have create colors selves. here's 1 such function can calculate lighter colors
fadecolors <- function(colors, steps=4) { rr <- col2rgb(colors) unlist(map(function(a) { rgb( seq(255, a[1],length.out=steps+1)[-1], seq(255,a[2],length.out=steps+1)[-1], seq(255,a[3],length.out=steps+1)[-1], maxcolorvalue=255) }, as.data.frame(rr))) } colors <- c("cornflowerblue","cornsilk4","red","orange") barplot(data2, legend= rownames(data2), beside= true,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,3000), col=fadecolors(colors))
this results in
basically idea add amount of white (in rgb scale) each color. there more sophisticated ways choose colors out there.
Comments
Post a Comment