1

I am trying to make a geom_tile of datasets with different number of variables. However, I want to plot them right next to each other and therefore I want the width and height of the tiles to be the same.

Is there a way to specify this in inches or cm?

I was looking for solutions and found coord_fixed(ratio=1), but that didn't solve the problem completely.

Example of two different dataframes:

df <- data.frame(
  x = rep(c(2, 5, 7, 9, 12), 2),
  y = rep(c(1, 2), each = 5),
  z = factor(rep(1:5, each = 2)),
  w = rep(diff(c(0, 4, 6, 8, 10, 14)), 2)
)
df <- expand.grid(x = 0:5, y = 0:5)
df$z <- runif(nrow(df))
p1 <- ggplot(df, aes(x, y, fill = z)) + geom_raster() +
coord_fixed(ratio=1)
p1 

df2=data.frame(x = rep(c("x","y","z"),3), 
               y=c("a","b","c","b","c","a","c","a","b"),
               z=c(0,1,0,1,1,1,0,0,1))

p2 <- ggplot(df2, aes(x, y)) + geom_tile(aes(fill = z)) +
coord_fixed(ratio=1)
p2 
GabrielMontenegro
  • 683
  • 1
  • 6
  • 21

0 Answers0