简体   繁体   English

R中没有标题/标签的图

[英]Plots without titles/labels in R

In R is there any way to produce plots which have no title and which use the space the title would otherwise have taken up? R中,有什么方法可以生成没有标题的图,并使用标题原本会占用的空间?

In plot() , main , sub , xlab , and ylab all default to NULL , but this just leaves blank space where they would have been, ditto for setting them to ''. plot()mainsubxlabylab都默认为NULL ,但这仅留了空白,将它们设置为”。 It would be nice if not including them meant that the entire plot space was utilized rather than leaving extra empty space on the edges. 如果不包括它们,那就意味着可以利用整个绘图空间,而不是在边缘保留多余的空白,那将是很好的。 This is all especially relevant in printing plots to file devices like pdf() , png() , etc. 这在将绘图打印到pdf()png()等文件设备时特别重要。

See tip 7 about adjusting the margins. 有关调整边距的信息,请参见技巧7

Excerpt: 摘抄:

To remove the space reserved for labels, use par(mar=...). 要删除为标签保留的空间,请使用par(mar = ...)。 For example 例如

png(file="notitle.png",width=400, height=350)
par(mar=c(5,3,2,2)+0.1)
hist(rnorm(100),ylab=NULL,main=NULL)
dev.off()

If you're willing to entertain an alternate plotting package, ggplot2 does this automatically when you set xlab / ylab to NULL (and there is no plot title/ main by default). 如果您愿意接受一个替代的绘图程序包, 那么当您将xlab / ylab设置为NULL (并且默认情况下没有绘图标题/ main )时, ggplot2会自动执行此操作。 For simple plots, just require(ggplot2) and replace plot by qplot . 对于简单的绘图,只需require(ggplot2)并用qplot替换plot

Really, ggplot2 is the most fun I've had with plotting in years and I can't resist the opportunity to evangelize it to everyone I meet. 确实,ggplot2是我多年来进行绘图所获得的最大乐趣,我无法抗拒将它传播给与我见面的每个人的机会。 :-) :-)

With lattice, it's just a matter of setting the xlab, ylab, and main arguments to NULL: 使用格子时,只需将xlab,ylab和主要参数设置为NULL即可:

library(lattice)
bwplot(rnorm(100),xlab=NULL,ylab=NULL,main=NULL)
plot(anything, main=NULL)

仍然有效。

I usually use 我通常使用

par(mar=c(1,1,1,1))

when I keep the border to a minimum. 当我将边界最小化时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM