2016-09-23 8 views
0

gridの練習目的では、プロットシンボルを調整しようとしています。考え方は、最小値/最大値を垂直線で結び、両方のシンボルに、輪郭のない同じ色の塗りつぶし線を付けることです。R :: 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

まず、問題のカップル:
1. pchgparパラメータではありません - gparpchを移動します。
2. pch = 2には 'col'がありますが、 'fill'はありません。 fillと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")) 
関連する問題