簡體   English   中英

ggplot2中ggfluctuation的顏色范圍

[英]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

情節p1

情節p2

情節p2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM