[英]Use facet_wrap in R
我在這個答案中嘗試了這個方法,使用facet在我的熱圖的“區域”之間包含白線。 這是我使用ChickWeight數據集時遇到的同樣問題。
library(reshape)
library(ggplot2)
ChickWeight.long <- melt(ChickWeight, id = c("Chick", "Diet"))
#Non-split heatmap
ggplot(ChickWeight.long, aes(x = Chick, y = variable, fill=value)) +
geom_tile(colour="white",size=0.1) + #add grid lines between the tiles
xlab("Chick") + ylab("") + labs(fill = "weight") +
theme_minimal()
這是我原來的情節,我喜歡垂直線來更好地區分x軸上的事物組(在這種情況下,雞)
#Attempt of split heatmap
ggplot(ChickWeight.long, aes(x = Chick, y = variable, fill=value)) +
facet_wrap(~Diet) +
geom_tile(colour="white",size=0.1) + #add grid lines between the tiles
xlab("Chick") + ylab("") + labs(fill = "weight") +
theme_minimal()
我讓Chick
成為一個numeric
變量並允許x標度自由。
ChickWeight.long$Chick <- as.numeric(as.character(ChickWeight.long$Chick))
ggplot(ChickWeight.long, aes(x = Chick, y = variable, fill=value)) +
facet_wrap(~Diet, scale = "free_x") +
geom_tile(colour="white",size=0.1) + #add grid lines between the tiles
xlab("Chick") + ylab("") + labs(fill = "weight") +
theme_minimal()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.