[英]colour range of ggfluctuation in ggplot2
我試圖在ggfluctuation
中使用ggplot2
兩個熱圖。 熱圖的兩個表具有不同的最大值(假設為0.8和0.9)。 為了使它們具有可比性,我想知道如何使它們的顏色從0變為1。
不要使用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
p2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.