当面板中的绘图具有不同的轴尺寸时，如何确保一致的轴缩放？

问题描述投票：0回答：1

``p3``

``````# Load packages
library(ggplot2)
library(patchwork)

# Define plots
p1 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 3)) +
ggtitle("p1")

p2 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 3)) +
ggtitle("p2")

p3 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 6)) +
ggtitle("p3")

p4 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 3)) +
ggtitle("p4")

p5 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 3)) +
ggtitle("p5")

p6 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 1.5)) +
ggtitle("p6")

p7 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 1.5)) +
ggtitle("p7")

p8 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 1.5)) +
ggtitle("p8")

# Set desired design
design <- "AAABBB
CCCCCC
DDDEEE
FFGGHH"

# Plot panel with specific design
p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 +
plot_layout(design = design)
``````
r ggplot2 axis
1个回答
0

``coord_fixed``

``````# Load packages
library(ggplot2)
library(patchwork)

# Define plots
p1 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 3)) +
coord_fixed(ratio = 0.125) +
ggtitle("p1")

p2 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 3)) +
coord_fixed(ratio = 0.125) +
ggtitle("p2")

p3 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 6)) +
coord_fixed(ratio = 0.125) +
ggtitle("p3")

p4 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 3)) +
coord_fixed(ratio = 0.125) +
ggtitle("p4")

p5 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 3)) +
coord_fixed(ratio = 0.125) +
ggtitle("p5")

p6 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 1.5)) +
coord_fixed(ratio = 0.125) +
ggtitle("p6")

p7 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 1.5)) +
coord_fixed(ratio = 0.125) +
ggtitle("p7")

p8 <- ggplot() +
scale_y_continuous(limits = c(0, 6)) +
scale_x_continuous(limits = c(0, 1.5)) +
coord_fixed(ratio = 0.125) +
ggtitle("p8")

# Set desired design
design <- "AAABBB
CCCCCC
DDDEEE
FFGGHH"

# Plot panel with specific design
p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 +
plot_layout(design = design, heights = 100)
``````