对于grid
练习目的,我正在尝试调整情节符号。我们的想法是将最小值/最大值与垂直线连接起来,并给出符号和值。在没有可见轮廓的情况下排列相同的颜色。
我已经找到了大部分步骤。我的问题是删除符号轮廓并更改符号。
library(grid)
n <- 10
mins <- 10*runif(n)
maxs <- mins + 5*runif(n)
grid.newpage()
pushViewport(plotViewport(c(5.1, 4.1, 4.1, 2.1)))
vp <- dataViewport( xData = 1:n , yData = c(mins,maxs) , name = "theRegion")
pushViewport(vp)
grid.rect()
grid.points(1:n,mins , gp = gpar(pch=2,col="blue",fill="blue"))
grid.edit("dataSymbols",pch=2)
# --------------------------------
# Error in editDLfromGPath(gPath, specs, strict, grep, global, redraw) :
# 'gPath' (dataSymbols) not found
# --------------------------------
grid.points(1:n,maxs, gp = gpar(pch=2,col="yellow"))
grid.xaxis()
grid.yaxis()
for(i in 1:n){
grid.lines(x = unit(c(i,i),"native"),
y = unit(c(mins[i],maxs[i]),"native"),
gp = gpar(col = "green",lwd=6))
}
答案 0 :(得分:0)
首先,有几个问题:
1. pch
不是gpar
参数 - 将pch
移到gpar
之外。
2. pch = 2有一个&#39; col&#39;但没有填充#39;填充和col的三角形符号是pch = 24
3.如果要编辑命名的grob,则需要具有该名称的grob。
library(grid)
n <- 10
mins <- 10*runif(n)
maxs <- mins + 5*runif(n)
grid.newpage()
pushViewport(plotViewport(c(5.1, 4.1, 4.1, 2.1)))
vp <- dataViewport(xData = 1:n, yData = c(mins,maxs), name = "theRegion")
pushViewport(vp)
grid.rect()
# Symbols are triangles with blue border and yellow fill.
# Note the grob's name
grid.points(1:n, mins, pch = 24, gp = gpar(col = "blue", fill = "yellow"), name = "dataSymbols")
# Edit that grob so that the symbols do not have a border
grid.edit("dataSymbols", gp = gpar(col = NA))
# Edit that grob so that the symbol changes to pch = 2
grid.edit("dataSymbols", pch = 2)
# OOPS! The symbols have only a fill assigned, but pch = 2 does not have a fill
# So, give the symbols a blue border
grid.edit("dataSymbols", gp = gpar(col = "blue"))