代码之家  ›  专栏  ›  技术社区  ›  b786

更改sjPlot::plot_mode()输出的vline粗细和字体大小

  •  0
  • b786  · 技术社区  · 3 年前

    我正试图改变plot_mode()图的美学,但我正在努力。具体来说,我想:

    • 使1:1的线(vline?)变厚
    • 增加标签的字体大小

    使用以下代码时的当前图形输出:

    以下是我当前使用的代码:

    library(lme4)
    library(ggplot2)
    library(sjPlot)
    
    # Run the model
    plotModel <- glmer(used ~ BareGround + ConiferTreeCanopy + DeciduousTreeCanopy + 
                              Developed + MesicGrass + MesicShrub + Water + XericGrass + 
                              XericShrub + (1|id) + (1|month), 
                       family = binomial(link = "logit"), 
                       data = plotData, na.action="na.fail")
    
    # Plot the results
    set_theme(base = theme_light())
    
    state1plot <- plot_model(plotModel, show.values = TRUE, show.p = FALSE, 
                             value.offset = 0.3, title = "", 
                             axis.labels = c("Xeric Shrubs", "Xeric Grasses", "Water", 
                                             "Mesic Shrubs", "Mesic Grasses", "Developed", 
                                             "Deciduous Tree Canopy", "Conifer Tree Canopy", 
                                             "Bare Ground"), 
                              axis.lim = c(0.01, 20), 
                              colors = c("#C43302", "#EDAA25"), 
                              vline.color = "#061423", 
                              dot.size = 8, line.size = 3) + 
                   theme(text = element_text(size = 20))
    
    state1plot 
    
    1 回复  |  直到 3 年前
        1
  •  0
  •   stefan    3 年前

    没有找到任何直接通过 plot_model 。但一种选择是操纵 ggplot 对象。为此,您首先必须计算 hline text 层。然后设置 size 直接通过 aes_params 要素

    由于您没有提供示例数据,我使用的默认示例之一来自 ?lme4::glmer :

    library(lme4)
    #> Loading required package: Matrix
    library(ggplot2)
    library(sjPlot)
    
    # Run the model
    plotModel <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
      data = cbpp, family = binomial
    )
    
    # Plot the results
    set_theme(base = theme_light())
    state1plot <- plot_model(plotModel,
      show.values = TRUE, show.p = FALSE,
      value.offset = 0.3, title = "",
      axis.labels = c(
        "Xeric Shrubs", "Xeric Grasses", "Water", "Mesic Shrubs",
        "Mesic Grasses", "Developed", "Deciduous Tree Canopy",
        "Conifer Tree Canopy", "Bare Ground"
      ), axis.lim = c(0.01, 20), colors = c("#C43302", "#EDAA25"),
      vline.color = "#061423", dot.size = 8, line.size = 1
    )  + 
      theme(text = element_text(size = 20))
    
    # vline
    state1plot$layers[[1]]$aes_params$size <- 4
    # labels
    state1plot$layers[[4]]$aes_params$size <- 8
    
    state1plot
    

    推荐文章