【问题标题】:break axis labels in R (Using sjp.frq function)在 R 中断开轴标签(使用 sjp.frq 函数)
【发布时间】:2018-10-30 15:11:44
【问题描述】:

我正在使用sjp.frq 函数制作一些频率图,但是轴标签太大了,我想将它们分成两行。 显示轴标签是一个在另一个顶部。我该如何更改?

感谢您的帮助!

library(sjPlot)
library(sjmisc)

set_theme(base = theme_classic(),  axis.title.size = 0,  geom.label.size = 4.5, 
                  axis.textsize.x = 1.1, axis.textsize.y = 1.1 )

sjp.frq(base$x, type = c("bar"), sort.frq = c("desc"), geom.colors = "grey")

【问题讨论】:

    标签: r graph axis-labels frequency-analysis


    【解决方案1】:

    另外,如果你想将长标签换成更多行,你可以使用wrap.labels-argument:

    sjp.frq(base$x, wrap.labels = 10)
    

    或者你改变轴标签的角度。 sjp.frq() 返回一个 data 和一个 plot 对象,因此您可以轻松添加 ggplot-layers,或者添加类似 label_angle() 的函数:

    sjp.frq(efc$e42dep)$plot + label_angle(90)
    

    【讨论】:

      【解决方案2】:

      虽然没有给出示例数据,但这里有两个可能有效的修复方法

      library(sjPlot)
      library(sjmisc)
      
      set_theme(base = theme_classic(),  axis.title.size = 0,  geom.label.size = 4.5, 
                        axis.textsize.x = 1.1, axis.textsize.y = 1.1 )
      
      sjp.frq(base$x, type = c("bar"), sort.frq = c("desc"), geom.colors = "grey",coord.flip =TRUE) #Flip the corrdinate and check if that avoids the overlap.
      

      如果上述方法不起作用,请尝试如下设置axis.angle.x参数

      library(sjPlot)
      library(sjmisc)
      
      set_theme(base = theme_classic(),  axis.title.size = 0,  geom.label.size = 4.5, 
                        axis.textsize.x = 1.1, axis.textsize.y = 1.1,axis.angle.x = 45 )#this should slant the text to avoid the overlap
      
      sjp.frq(base$x, type = c("bar"), sort.frq = c("desc"), geom.colors = "grey")
      

      【讨论】:

        猜你喜欢
        • 2017-04-13
        • 1970-01-01
        • 2012-05-24
        • 2013-11-05
        • 2020-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多