当尝试使用
+
中的 patchwork
添加两个 ggplot 对象(图)时,我收到如下所示的错误。可能是什么问题?
require(patchwork)
ex.df <- data.table(
x1 = rnorm(1000, 20, 50),
x2 = rnorm(1000, 4, 5)
)
plt1 <- ex.df |>
ggplot() +
geom_density(aes(x = x1))
plt2 <- ex.df |>
ggplot() +
geom_density(aes(x = x2))
plt1 + plt2
即使我使用
wrap_plots
功能也会发生这种情况
与
data.frame
:
library(ggplot2)
require(patchwork)
ex.df <- data.frame(
x1 = rnorm(1000, 20, 50),
x2 = rnorm(1000, 4, 5)
)
plt1 <- ex.df |>
ggplot() +
geom_density(aes(x = x1))
plt2 <- ex.df |>
ggplot() +
geom_density(aes(x = x2))
plt1 + plt2
创建于 2024-03-17,使用 reprex v2.1.0