我窃取了下面的例子(原始发现的http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/81-ggplot2-easy-way-to-mix-multiple-graphs-on-the-same-page/#align-plot-panels)。输出中心在图中对齐表格,但我希望将表格与上图的x轴标签对齐。做这件事最简单的方法是什么?
library("ggpubr")
library("grid")
library("gridExtra")
# Density plot of "Sepal.Length"
#::::::::::::::::::::::::::::::::::::::
density.p <- ggdensity(iris, x = "Sepal.Length",
fill = "Species", palette = "jco")
# Draw the summary table of Sepal.Length
#::::::::::::::::::::::::::::::::::::::
# Compute descriptive statistics by groups
stable <- desc_statby(iris, measure.var = "Sepal.Length",
grps = "Species")
stable <- stable[, c("Species", "length", "mean", "sd")]
# Summary table plot, medium orange theme
stable.p <- ggtexttable(stable, rows = NULL,
theme = ttheme("mOrange"))
p <- arrangeGrob(density.p, stable.p,
ncol = 1,
heights = c(2, 1))
grid.draw(p)这是输出。

这是我想要的输出(表格向右移动以与x轴标签对齐)。

发布于 2021-01-22 01:02:40
尝试使用patchwork
library(patchwork)
#Code
G <- density.p/stable.p输出:

或者这样:
#Code 2
G <- density.p/(plot_spacer()+stable.p)输出:

https://stackoverflow.com/questions/65831927
复制相似问题