在R中使用facet\u wrap

在R中使用facet\u wrap,r,ggplot2,facet-wrap,R,Ggplot2,Facet Wrap,我尝试了使用刻面的方法,在我的热图的“区域”之间包含白线。这里的问题与我使用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)) +

我尝试了使用刻面的方法,在我的热图的“区域”之间包含白线。这里的问题与我使用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() 
这就是我得到的。我想把被压扁的地块拉长到整个长度。我做错了什么?

我制作了一个
Chick
a
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() 

ChickWeight.long$Chick我不知道你能像那样改变体重!干得好,伙计!也许可以将小鸡变成整数,因为我认为它们只是鸡id:)您的解决方案也可以通过简单地将
scales=“free”
添加到OP的原始绘图命令中来工作。谢谢。但我其实是希望把它们排在同一排。基本上只在一个单独的长热图中添加白线。但这可能不适用于facet,我将在网格中绘制多个绘图以使facet在一行中对齐,将
nrow=1
添加到
facet\u wrap
,或切换到
facet\u网格
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()