我正在尝试使用不同数量的变量制作geom_tile
个数据集。但是,我想将它们彼此相邻绘制,因此我希望切片的宽度和高度相同。
有没有办法以英寸或厘米为单位指定?
我一直在寻找解决方案并找到coord_fixed(ratio=1)
,但这并没有完全解决问题。
两个不同数据帧的示例:
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