莱迪思的`panel.rug`产生不同的线长和宽的情节 [英] Lattice's `panel.rug` produces different line length with wide plot
问题描述
在边距包含panel.rug()
的点阵中生成宽图时,在 rugged 边距中的线的长度在y轴上比在x轴上长:
When producing a wide plot in lattice with margins that include panel.rug()
, the length of the lines in rugged margins is longer in the y-axis than x-axis:
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 线当绘图为正方形时,长度将相同.
I would like those rug lines in x- and y-axes to be the same length regardless of the shape of a plot (note: right now the rug lines will only be the same length when the plot is square).
推荐答案
使用晶格,只需将panel.rug
使用的坐标系从其默认("npc"
)更改为"snpc"
:
With lattice, just change the coordinate system used by panel.rug
from its default ("npc"
) to "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
来描述这两个坐标系的含义:
To see why this gets you what you want, refer to ?unit
for its description of what those two coordinate systems mean:
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).
这篇关于莱迪思的`panel.rug`产生不同的线长和宽的情节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!