介绍
有几种方法可以缩放格点图元素的大小。一种选择是更改所有带有cex
属性的参数,另一种是更改fontsize
绘制所有内容的基础。您想要的解决方案是后者,您将在一分钟内看到,但了解如何通过par.settings
参数影响绘图的各个组件也很有指导意义,因为您可能希望在设置时调整应用于各个组件的相对缩放fontsize
.
tl:博士
使用来自@Andrie's Answer 的示例图
require(lattice)
plt <- xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
type = "a",
auto.key = list(space = "right", points = FALSE, lines = TRUE))
设置fontsize
参数,一个包含组件的列表text
和points
,它定义了这两个关键绘图元素的基本尺寸,所有其他绘图家具都是从这些元素生成的。
update(plt, par.settings = list(fontsize = list(text = 8, points = 4)))
(在 150 像素 x 200 像素 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)
使用gridExtra包在同一设备上排列两个格子图,我们可以看到所有这些的效果:
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
设置中获取队列。同样,在矢量设备上绘制这些将产生更好的输出。