我正在将 R 与 cygwin 一起使用,并试图绘制一些基本图形。这是 Paul Murrell 的一篇论文中的一个简单示例:
library(grid)
x <- rnorm(50)
y <- x + rnorm(50, 1, 2)
rx <- range(x)
dx <- diff(rx)
ry <- range(y)
dy <- diff(ry)
max <- max(rx, ry)
min <- min(rx, ry)
r <- c(min(rx, ry), max(rx, ry))
d <- diff(r)
scale <- r + c(-1, 1) * d * 0.05
extscale <- c(min(scale), max(scale) + diff(scale) * 1/3)
lay <- grid.layout(2, 2,
widths = unit(c(3, 1), "inches"),
heights = unit(c(1, 3), "inches"))
vp1 <- viewport(w = unit(4, "inches"), h = unit(4, "inches"),
layout = lay, xscale = extscale, yscale = extscale)
grid.newpage()
pushViewport(vp1)
grid.rect()
grid.xaxis()
grid.text("Test", y = unit(-3, "lines"))
grid.yaxis()
grid.text("Retest", x = unit(-3, "lines"), rot = 90)
vp2 <- viewport(layout.pos.row = 2, layout.pos.col = 1,
xscale = scale, yscale = scale)
pushViewport(vp2)
grid.lines()
grid.points(x, y, gp = gpar(col = "blue"))
这情节很好。但是,如果我将以下行添加到程序中:
grid.lines(x, y, gp = gpar(col = "red"))
线条到处都是。我原以为线条会按顺序连接这些点。我写的一些代码也有类似的问题,但是线条绘制得很好,但点却没有。
将不胜感激任何帮助。谢谢。