您好我想绘制以下数据帧。
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")
然而,我希望每个x因子都有自己的颜色渐变,所以理想情况下rna是蓝色到白色而dna是红色到白色。反正有没有这样做?如果不可能有不同的梯度,那么仅仅是不同的尺度呢?谢谢!
答案 0 :(得分:1)
ggplot(iris, aes(Sepal.Length,
Petal.Width,
color = Species,
alpha = Sepal.Width)) +
geom_point(size = 4)
另见:How to create a continuous legend (color bar style) for scale_alpha?
答案 1 :(得分:1)