将函数forest_model中的x轴更改为对数

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

我已经安装了这个物流模型:

model <- glm(Groupe~Cluster+age, family="binomial",data= base)

我想使用以下代码将结果呈现为森林图:

forest_model(model, exponentiate=TRUE)

但我希望 x 轴刻度为对数,但我无法做到。

感谢您的帮助或其他替代方案。

r random-forest
1个回答
0
投票

一个潜在的选择是使用 ggplotify 包“捕获”图形,然后通过 ggplot2

scale_x_continuous()
函数转换 x 轴,例如

library(tidyverse)
#install.packages("forestmodel")
library(forestmodel)
library(ggplotify)

# example data
cohort <- data.frame(Age = c(43, 39, 34, 55, 70, 59, 44, 83, 76, 44, 
                             75, 60, 62, 50, 44, 40, 41, 42, 37, 35, 55, 46), 
                     Group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                         1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
                                       levels = c("1","2"), class = "factor"))

age.glm <- glm(Age ~ Group, data = cohort)
forest_plot <- forest_model(age.glm, exponentiate=TRUE)
#> Resized limits to included dashed line in forest panel
forest_plot


forest_ggplot <- as.ggplot(forest_plot)
forest_ggplot +
  scale_x_continuous(transform = "pseudo_log", limits = c(0.1,2.2))
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.

创建于 2024-04-30,使用 reprex v2.1.0

您可能需要调整限制以获得所需的图形尺寸。这种方法适用于您的实际数据吗?

© www.soinside.com 2019 - 2024. All rights reserved.