簡體   English   中英

在R中使用facet_wrap

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

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