在 ggplot2 中使用小字体

sil*_*ter 0 pdf r ggplot2

我尝试使用 ggplot 进行绘图。因此,在 R-Studio 中绘图时,evereting 是可以的。但是当我尝试制作 PDF 并将此图从 R 输出到外部时出现问题。即字母重叠。你可以在下面的图片中看到,我已经用黄色标记了。

在此处输入图片说明

对于绘图,我使用这行代码

# Plotting with ggplot2
        p<-ggplot(data_plot, aes(x=y, y=z)) +
           stat_pareto(point.color = "red",
                      point.size = 3,
                      line.color = "black",
                      size.line = 1,
                      bars.fill = c("blue", "orange")
          ) +
          xlab(' ') +
          ylab('')
        
       # Output in pdf
        pdf(file=paste("out.pdf",sep=""),width=10, height=5)
        
        op <- par(mgp=c(1,0,0),mar=c(2, 2, 1, 1),# Room for the title and legend: 1_bottom,2_left,3_up,4_right
                  mfrow=c(1,2))
        
        plot(p)
Run Code Online (Sandbox Code Playgroud)

那么任何人都可以帮助获得更好的 x 轴值、较小字体的字母或其他任何东西并修复此错误吗?

All*_*ron 5

最新版本的 ggplot 允许您通过指定n.dodgeinguide_axis来修复重叠的 x 轴标签来避开轴标签。

比较这个情节:

library(ggplot2)

p <- ggplot(data.frame(y = 1/1:10, x = paste("long label", 0:9)), aes(x, y)) +
      geom_col(fill = "royalblue")
p
Run Code Online (Sandbox Code Playgroud)

对此:

p + scale_x_discrete(guide = guide_axis(n.dodge = 2))
Run Code Online (Sandbox Code Playgroud)