当在边距包含 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 轴上的地毯线长度相同,无论绘图的形状如何(注意:现在地毯线仅当绘图为正方形时长度才会相同)。
最佳答案
使用lattice,只需将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).
关于r - Lattice 的 `panel.rug` 产生不同的线长度和宽图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33222841/