作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 R 在一张图像中组合表格和绘图的首选技术是什么?我记得几个月前使用过 tableGrob() 和 patchwork 或 cowplot 但不记得细节。
此示例使用 ggstatsplot 包。我想将相关系数添加到相关图(相关图)中。
if (!('ggstatsplot' %in% installed_packages)) {
devtools::install_github('https://github.com/IndrajeetPatil/ggstatsplot')
}
needed_pkgs <- setdiff(c('ggstatsplot', 'statsExpressions',
'dplyr', 'nnet', 'MASS'),
installed_packages)
if (length(needed_pkgs) > 0) {
install.packages(needed_pkgs)
}
library(ggstatsplot)
library(statsExpressions)
library(dplyr)
library(nnet)
library(MASS)
utils::example(topic = birthwt, echo = FALSE)
# model
bwt.mu <-
nnet::multinom(
formula = low ~ .,
data = bwt,
trace = FALSE
)
original_cols <- colnames(bwt)
bwt.mu_coefstats <- ggcoefstats(x = bwt.mu, output = "tidy") %>%
# skipping first row = intercept
slice(2:n()) %>%
dplyr::filter(term %in% original_cols) %>%
arrange(desc(p.value)) %>%
dplyr::select(term, estimate, p.value)
# Correlogram
cor_plot_out <-
ggstatsplot::ggcorrmat(bwt %>% dplyr::select(low, lwt, age))
想结合
bwt.mu_coefstats
cor_plot_out
最佳答案
关键要素是tableGrob()
来自 gridExtra
包裹!
我们可以使用 grid.arrange()
.
对于表使用 tableGrob()
创建一个类似于数据框绘图的表格。然后你可以用 grid.arrange()
功能。
library(gridExtra)
bwt.mu_coefstats <- tableGrob(
bwt.mu_coefstats,
theme = ttheme_default(
base_size = 10,
base_colour = "grey25",
parse = T
),
rows = NULL
)
grid.arrange(cor_plot_out, bwt.mu_coefstats,
heights = c(10, 4))
library(patchwork)
cor_plot_out + bwt.mu_coefstats
关于r - 将相关图与系数表相结合(ggplot2 -> ggstatsplot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67876564/
使用 R 在一张图像中组合表格和绘图的首选技术是什么?我记得几个月前使用过 tableGrob() 和 patchwork 或 cowplot 但不记得细节。 此示例使用 ggstatsplot 包。
我正在使用 ggstatsplot() 创建一些图表。但是,我遇到了一个变量的问题:我不断收到“提供给连续刻度的离散值”错误,我无法弄清楚原因。 我已经尝试过 as.numeric 并创建新变量,将
我正在尝试使用 grouped_ggwithinstats()来自 ggstatsplot 的函数包裹: 我有这个数据集: df You can cite this package as: #>
我是一名优秀的程序员,十分优秀!