ggfluctuation
in で 2 つのヒートマップを使用しようとしていggplot2
ます。ヒートマップの 2 つのテーブルの最大値は異なります (0.8 と 0.9 を想定)。それらを比較できるようにするために、両方の色を0から1まで変化させる方法を知りたい.
質問する
452 次
1 に答える
3
使用しないでくださいggfluctuation
; 非推奨です。以下のように使用すると、希望する効果が得geom_tile()
られます。複数のプロットがある場合は、1つのカラースケールを作成し、それを各プロットに順番に適用します。
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
結果:2つのプロット
プロットp1
プロットp2
于 2013-03-01T21:13:46.150 に答える