当使用包含panel.rug()
的边距在格子中生成宽图时,粗糙边距中的线条长度在y轴上比x轴更长:
library(lattice)
png(width=800, height=400)
xyplot(Fertility ~ Education, swiss, panel = function(x, y,...) {
panel.xyplot(x, y, col=1, pch=16)
panel.rug(x, y, col=1, end= ...)})
dev.off()
我希望x轴和y轴上的 rug 线条长度相同,而不管图形的形状如何(注意:现在 rug 线条当情节是正方形时,只会是相同的长度。
答案 0 :(得分:2)
使用点阵,只需将panel.rug
使用的坐标系从默认值"npc"
更改为"snpc"
:
library(lattice)
## png(width=800, height=400)
xyplot(Fertility ~ Education, swiss, panel = function(x, y,...) {
panel.xyplot(x, y, col=1, pch=16)
panel.rug(x = x, y = y,
x.units = rep("snpc", 2), y.units = rep("snpc", 2),
col=1, end= ...)
})
## dev.off()
要查看为什么这可以获得您想要的内容,请参阅?unit
,了解这两个坐标系的含义:
Possible ‘units’ (coordinate systems) are:
‘"npc"’ Normalised Parent Coordinates (the default). The origin
of the viewport is (0, 0) and the viewport has a width and
height of 1 unit. For example, (0.5, 0.5) is the centre of
the viewport.
‘"snpc"’ Square Normalised Parent Coordinates. Same as Normalised
Parent Coordinates, except gives the same answer for
horizontal and vertical locations/dimensions. It uses the
_lesser_ of npc-width and npc-height. This is useful for
making things which are a proportion of the viewport, but
have to be square (or have a fixed aspect ratio).