2016-09-23 3 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 매개 변수 아니다 - gpar 외부 pch 이동합니다.
2. pch = 2에는 'col'이 있지만 '채우기'는 없습니다. 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"))