Lattice 的 `panel.rug` 产生不同的线长和宽图
Lattice's `panel.rug` produces different line length with wide plot
当在格子中生成包含 panel.rug()
边距的宽图时,rugged 边距中的线条长度在 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 行只有在绘图为正方形时才具有相同的长度)。
使用 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).
当在格子中生成包含 panel.rug()
边距的宽图时,rugged 边距中的线条长度在 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 行只有在绘图为正方形时才具有相同的长度)。
使用 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).