我在this answer中尝试使用方法在我的热图的“区域”之间包含白线。这是我使用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()
答案 0 :(得分:3)
我将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()