Intro
有多种方法可以缩放格子图元素的大小。一种选择是更改所有需要的参数cex
属性,另一个是改变基数fontsize
一切都被吸引。您想要的解决方案是后者,您很快就会看到,但了解如何通过以下方式影响绘图的各个组成部分也很有启发性:par.settings
参数,因为您可能希望在设置时定制应用于各个组件的相对缩放fontsize
.
tl:dr
使用@Andrie's Answer 中的示例图
require(lattice)
plt <- xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
type = "a",
auto.key = list(space = "right", points = FALSE, lines = TRUE))
Set the fontsize
参数,包含组件的列表text
and points
,它定义了这两个关键绘图元素的基本尺寸,所有其他绘图家具都是从这些元素生成的。
update(plt, par.settings = list(fontsize = list(text = 8, points = 4)))
(在 150px x 200px PNG 光栅设备上渲染)。
设定个别cex
地块家具特定项目的参数
需要注意的一件事是,格子图的外观是由返回的整个参数流控制的trellis.par.get()
> thm <- trellis.par.get()
> str(thm, max = 1)
List of 35
$ grid.pars : list()
$ fontsize :List of 2
$ background :List of 2
$ panel.background :List of 1
$ clip :List of 2
$ add.line :List of 4
$ add.text :List of 5
$ plot.polygon :List of 5
$ box.dot :List of 5
$ box.rectangle :List of 5
$ box.umbrella :List of 4
$ dot.line :List of 4
$ dot.symbol :List of 5
$ plot.line :List of 4
$ plot.symbol :List of 6
$ reference.line :List of 4
$ strip.background :List of 2
$ strip.shingle :List of 2
$ strip.border :List of 4
$ superpose.line :List of 4
$ superpose.symbol :List of 6
$ superpose.polygon:List of 5
$ regions :List of 2
$ shade.colors :List of 2
$ axis.line :List of 4
$ axis.text :List of 5
$ axis.components :List of 4
$ layout.heights :List of 19
$ layout.widths :List of 15
$ box.3d :List of 4
$ par.xlab.text :List of 5
$ par.ylab.text :List of 5
$ par.zlab.text :List of 5
$ par.main.text :List of 5
$ par.sub.text :List of 5
其中许多因素会影响所绘制对象的大小和注释中使用的文本。您需要修改所有适当的设置并仅将这些设置作为列表传递给par.settings()
。这是缩放 @Andrie 的示例图的示例:
CEX <- 0.5
pset <- list(superpose.symbol = list(cex = CEX),
plot.symbol = list(cex = CEX),
par.sub.text = list(cex = CEX),
par.main.text = list(cex = CEX),
par.zlab.text = list(cex = CEX),
par.ylab.text = list(cex = CEX),
par.xlab.text = list(cex = CEX),
dot.symbol = list(cex = CEX),
box.dot = list(cex = CEX),
add.text = list(cex = CEX),
axis.text = list(cex = CEX))
plt2 <- update(plt, par.settings = pset)
使用网格额外包在同一设备上排列两个点阵图,我们可以看到所有这些的效果:
require("gridExtra") ## loads package:grid too
grid.arrange(plt, plt2, ncol = 2)
导致
所以现在(几乎)一切都已经规模化了。值得注意的一件有趣的事情是,这种方法没有缩放图例中线条的长度,也没有缩放刻度长度。请注意图的大小,每个子图的面积是相同的。然而,我们可以以更小的尺寸绘制整个图像:
这是合理的,并且在基于矢量的设备上渲染效果会更好(例如pdf()
)比光栅png()
我不得不在这里用它来说明。第二个图位于 150 像素 x 200 像素的设备上。
设置底座fontsize
控制整体缩放
有一种更简单的方法,那就是通过设置文本和点的基本字体大小fontsize
范围。其中默认值是:
> trellis.par.get("fontsize")
$text
[1] 12
$points
[1] 8
这些会影响绘图上的所有内容,因此我们可以缩小它们以达到设置所有其他设置的类似效果。
update(plt, par.settings = list(fontsize = list(text = 8, points = 4)))
产生
这是在相同尺寸上绘制的png()
设备如之前的图 2 所示。请注意边距如何调整,以便更好地缩放绘图。因此,我们不仅影响了之前更改的所有设置,还影响了绘图的其他部分(例如间距和刻度线),这些部分也从fontsize
设置。同样,在矢量设备上绘制这些将产生更好的输出。