![](/img/trans.png)
[英]Heatmap with geom_tile how to divide and reorder based on another factor without using facets
[英]geom_tile heatmap with different high fill colours based on factor
我有興趣在ggplot2中使用geom_tile
構建熱圖,該熱圖使用基於因子的不同漸變高顏色。
下圖創建了一個圖,其中各個圖塊根據xy_type
為藍色或紅色,但沒有漸變。
ggplot() +
geom_tile(data=mydata, aes(x=factor(myx), y=myy, fill=factor(xy_type))) +
scale_fill_manual(values=c("blue", "red"))
下面的圖不使用xy_type
因子來選擇顏色,但是我得到一個基於xy_avg_value
組漸變。
ggplot() +
geom_tile(data=mydata, aes(x=factor(myx), y=myy, fill=xy_avg_value))
有沒有一種技術可以混合這兩個圖? 我可以使用facet_grid(xy_type ~ .)
使用漸變創建此數據的單獨圖。 由於這最終將成為一個地圖(x~y坐標),我想找到一種方法在一個geom_tile
地圖中一起顯示不同的漸變。
一般來說, ggplot2不允許單一類型的多個比例(即多個顏色或填充比例),所以我懷疑這不是(容易)可能的。
我能想出的最接近的最近似是:
df <- data.frame(expand.grid(1:5,1:5))
df$z <- runif(nrow(df))
df$grp <- rep(letters[1:2],length.out = nrow(df))
ggplot(df,aes(x = Var1,y = Var2,fill = factor(grp),alpha = z)) +
geom_tile() +
scale_fill_manual(values = c('red','blue'))
但要獲得一個明智的傳奇將是艱難的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.