How can I color a specific bar on a chart (qplot, ggplot2)

I built a graph using qplot and I used the "fill" option to color the bars based on their values ​​(high = Red, med = purple, low = blue)

http://i.stack.imgur.com/raEzA.png

My code is:

x = qplot(as.character(exon),Divergence_from_Average, data=HRA_LR,     
  geom="histogram",fill=abs(Divergence_from_Average)) 
y = x +facet_grid(~probeset_id, scales="free_x", space= "free") + theme_bw() +     
  opts(title="GRP78/HSPA5  (HRN vs LR)") 

If I only need to color the stripes above 0.3 and leave the rest of the blank, how can I do this?

+5
source share
2 answers

You can customize this to suit your needs, but here is the basic concept:

, , . fill scale_colour_manual, . colour , .

#Sample data
df <- data.frame(
    divergence = rnorm(10), 
    exons = paste("E", sample(1:20, 10, TRUE), sep = ""), 
    probset_id = sample(letters, 10, FALSE) 
)

#Binary flag for fill
df$fill <- with(df, ifelse(divergence > .3, 1,0))


ggplot(data = df, aes(as.character(exons), divergence, fill = factor(fill))) +
    geom_histogram(colour = "red", legend = FALSE) +
    scale_fill_manual(values = c("1" = "red", "0" = "white"), legend = FALSE) +
    facet_grid(~ probset_id, scales="free_x", space= "free") +
    theme_bw() + opts(title="GRP78/HSPA5  (HRN vs LR)")

- . set.seed() , , :

enter image description here

+8

ggplot2

library(ggplot2)
data(tips)
qplot(day, data = tips, geom = 'blank') +  geom_bar(aes(fill = ..count.. > 65))
+1

All Articles