i have data frame d this:
track <- c(0,0,0,-1,1,1) length <- c(1,1,2,1,3,1) legend <- c("a","b","a","c","b","c") d <- data.frame(track,length,legend) d # track length legend # 0 1 # 0 1 b # 0 2 # -1 1 c # 1 3 b # 1 1 c i using code plot it:
ggplot(z, aes(x=track, y=length, fill=legend)) + geom_bar(stat='identity') + geom_point() + expand_limits(x=0,y=0) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) and graph looks this: 
however want assign color white variable b. manipulation possible? additionally using dummy data simplicity's sake in post. actual data using may have 10 or more different variables under legend, writing out each hex color doesn't clean option.
thank help
does produce you're after?
x <- length(levels(factor(legend))) x.colors <- hcl(h=seq(15,375,length=(x+1)),l=65,c=100)[1:x] x.colors[x] <- "white" ggplot(d, aes(x=track, y=length, fill=legend)) + geom_bar(stat='identity',colour="black") + geom_point() + expand_limits(x=0,y=0) + scale_fill_manual(values=x.colors) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour ="black")) i added scale_fill_manual() assigning colors a, b, , c. added colour="black" geom_bar(). try , without second part , see think.
Comments
Post a Comment