繁体   English   中英

控制R中图的标题参数

[英]control of title parameters of a plot in R

我试图设置一个共同的标题,以及4个组合子图的唯一常见xy轴标签:

dev.new( width =  9, height = 10)
layout( matrix( c( 0, 1, 1, 2, 3, 4, 2, 5, 6, 0, 7, 7 ), 4, 3, byrow = TRUE), widths = c( 1, 4, 4 ), heights = c( 1, 4, 4, 1 ) )
par( mar = c( 1, 0, 1, 0 ) )
plot( c(1:2), type = "n", xlab = "", ylab = "", axes = F, cex = 0.7 ) #general title 
title( main = "title", ps = 2 )
par( mar = c( 1, 0, 1, 1) )
plot( c(1:2), type = "n", xlab = "", ylab = "", axes = F, las = 2, cex = 0.7 ) #general y-label  
title( main = " y-label ", las = 0 )
par( cex= 0.9,  mar = c( 5, 1, 1, 2 ) )
plot( c(1:10), type="l", xlab = "A", ylab = "", axes = T, las = 1, cex = 0.7 ) # first    subplot 
par( cex= 0.9,  mar = c( 5, 1, 1, 3 ) )
plot( c(10:1), type ="l", xlab = "B", ylab = "", axes = T, las = 1, cex = 0.7 ) # second subplot
par( cex= 0.9,  mar = c( 5, 1, 1, 2 ) )
plot( c(1:10), type="l", xlab = "C", ylab = "", axes = T, las = 1, cex = 0.7 ) # third subplot
par( cex= 0.9,  mar = c( 5, 1, 1, 3 ) )
plot( c(1:2), type="l", xlab = "D", ylab = "", axes = T, las = 1, cex = 0.7 ) # fourth subplot
par(mar = c( 1, 0, 1, 0 ) )
plot( c(1:2), type = "n", xlab = "", ylab = "", axes = F, cex = 0.7 ) #general x-label
title( main = " x-label " )

如何控制这些标题的字体大小,位置和方向?

您正在寻找的是整个数字的外边距。 使用par(oma=...)设置它并使用mtext(..., outer=TRUE)添加轴标签和标题。

par(mfrow=c(2,2), oma=c(3,3,4,0), mar=c(4,2,1,1), las=1, cex=0.7)
plot(1:10, type="l", xlab="A", ylab="")
plot(10:1, type ="l", xlab="B", ylab="")
plot(1:10, type="l", xlab="C", ylab="")
plot(1:2, type="l", xlab="D", ylab="")
mtext("X-label", 1, 1, outer=TRUE)
mtext("Y-label", 2, 1, outer=TRUE, las=0)
mtext("Title", 3, 1, outer=TRUE, cex=2)

在此输入图像描述

请注意, 1:10 : 1:10相当于c(1:10)并且在par调用中,只需在面板AD中设置为常量的所有par设置一次。

暂无
暂无

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

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