Hi I would like to plot the following dataframe.
d<- data.frame (pid=c("d","b","c"), type=c("rna","rna","rna"), value = c(1,2,3) )
d2 <- data.frame (pid=c("d","b","c"), type=c("dna","dna","dna"), value = c(10,20,30) )
df <- rbind (d,d2)
ggplot(df, aes(y=pid, x=type ) ) + geom_tile(aes(fill = value),
colour = "white") + scale_fill_gradient(low = "white",
high = "steelblue")
This produces a plot that looks like this,
however, I would like to have each x factor have its own color gradient, so ideally rna is blue to white while dna is red to white. Is there anyway to do this? Of if different gradient is not possible, then what about just different scales? thanks!
Also see: How to create a continuous legend (color bar style) for scale_alpha?
Here is what it looks like applying @Brian's suggestion to your original example. You may want to rescale the
rna
anddna
value separately, to make the color ranges more comparable.