【问题标题】:x axis labels being cut off only when saving graph in r仅当将图形保存在 r 中时 x 轴标签才被切断
【发布时间】:2013-06-10 21:15:27
【问题描述】:

我正在尝试在 r 中创建条形图,但我遇到了 x 轴标签被切断的问题。但是,这仅在我将图形保存到文件时才会发生。如果我将它打印到图形设备上,它会显示所有标签,但是当我保存文件时,标签会被切断。

这里是重现问题的代码。

Captivate<-51.38
Challenge<-88.88889
Clarify<-80.55556
Confer<- 81.29085
Consolidate<-64.81481
Care<-68.51852
Control<-70.66993
Engagement<-66.17239

df<-rbind(Captivate, Challenge, Clarify, Confer, Consolidate, Care, Control, Engagement)

png("~/graph.png")
barplot(df, beside=TRUE, ylim=c(0,100),ylab="Percentage of Positive Answers ", space=.1, main="Some Title", 
        names.arg=c("Captivate", "Challenge", "Clarify", "Confer", "Consolidate", "Care", "Control", "Engagement"), las=2, axis.lty=1)
dev.off()

我尝试使用 par() 更改边距,但没有任何效果。

谁能告诉我我需要做什么才能显示完整的标签?

【问题讨论】:

    标签: r plot axis-labels


    【解决方案1】:

    启动新的图形设备会将 par 值重置为设备默认值,因此您需要在调用 png 后设置 mar:

    png("~/graph.png") ; par(mar=c(6, 4, 4, 2) + 0.1)
    barplot(df, beside=TRUE, ylim=c(0,100),
       ylab="Percentage of Positive Answers ", space=.1, main="Some Title", 
       names.arg=c("Captivate", "Challenge", "Clarify", "Confer", "Consolidate", "Care", "Control", "Engagement"), las=2, axis.lty=1)
    dev.off()
    

    【讨论】:

      猜你喜欢
      • 2018-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 2019-12-19
      • 2015-12-15
      • 2012-05-04
      相关资源
      最近更新 更多