Kev*_*vin 5 r ggplot2 gtable cowplot
我正在尝试coord_equal()使用cowplot::plot_grid()或将两个FACETED ggplot对象组合在一起,egg::ggarrange()并垂直对齐它们。
该egg::ggarrange()方法适用于UNFACETED地块,解决方案在此处发布。
但是,egg::ggarrange()当包含构面时,解决方案将失效。这些图已正确对齐,但是y轴的单位是x轴的单位的两倍。关于如何对此进行概括的任何建议?
dat1 <- data.frame(x = rep(1:10, 2), y = 1:20, z = rep(c("A", "B"), 10))
dat2 <- data.frame(x = 1:10, y = 1:10, z = rep(c("A", "B"), 5))
plot1 <- ggplot(dat1, aes(x=x, y=y)) +
geom_point() + coord_equal() + facet_wrap(~z)
plot2 <- ggplot(dat2, aes(x=x, y=y)) +
geom_point() + coord_equal() + facet_wrap(~z)
egg::ggarrange(plot1, plot2, ncol = 1)
Run Code Online (Sandbox Code Playgroud)
小智 3
这似乎是一个简单的修复,
library(egg)
b <- body(gtable_frame)
b[6] <- parse(text="if (fixed_ar) {
ar <- as.numeric(g$heights[tt[1]]) / as.numeric(g$widths[ll[1]])
height <- width * (ar / length(ll))
g$respect <- FALSE
}")
body(gtable_frame) <- b
assignInNamespace("gtable_frame", gtable_frame, ns = 'egg')
Run Code Online (Sandbox Code Playgroud)
