1

我正在尝试使用两个带有ggfluctuationin 的热图ggplot2。热图的两个表具有不同的最大值(假设为 0.8 和 0.9)。为了使它们具有可比性,所以我想知道如何使它们的颜色都在 0 到 1 之间变化。

4

1 回答 1

3

不要使用ggfluctuation; 它已被弃用。你想要的效果可以使用geom_tile()如下来实现。如果您有多个绘图,请创建一个色标并将其依次应用于每个绘图:

library("ggplot2")

# creat variable to flag whether diamond size is below mean
diamonds$small <- diamonds$carat < mean(diamonds$carat)

# create table suitable for plotting, with facets by size
d2 <- data.frame(table(diamonds$cut, diamonds$color, diamonds$small))
names(d2) <- c("cut", "color", "size", "freq")

# create colour scale
c.scale <- scale_fill_gradient(low = "white", 
                               high = "steelblue",
                               limits=c(min(d2$freq),
                                        max(d2$freq)))

# apply the same scale to different plots
p1 <- ggplot(d2[which(d2$size == TRUE),], aes(cut, color)) + 
    geom_tile(aes(fill = freq), colour="white") 

p1 + c.scale

p2 <- ggplot(d2[which(d2$size == FALSE),], aes(cut, color)) + 
    geom_tile(aes(fill = freq), colour="white") 

p2 + c.scale

结果:两个图

阴谋p1

情节 p1

阴谋p2

情节 p2

于 2013-03-01T21:13:46.150 回答