Reputation: 995
I tried the approach in this answer to use facets to include white lines between "zones" of my heatmap. Here's the same problem I have using the ChickWeight dataset.
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()
This is my original plot, I'd like vertical lines to better distinguish groups of things (in this case, chickens) in the x axis
#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()
This is what I get. I'd like the squished plots to be stretched the whole length. What am I doing wrong?
Upvotes: 1
Views: 2515
Reputation: 541
I made Chick
a numeric
variable and allowed the x scale to be free.
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()
Upvotes: 3