2017-04-11 7 views
0

ggplot 배경으로 사용되는 rastergrob 객체에 투명도를 추가하고 싶습니다.R - gprplot의 rastergrob 배경에 투명도 추가

여기에 내 코드

library(ggplot2) 
library(grid) 
library(ggthemes) 

reds <- c("brown", "red","orange","green","orange","red","brown","grey") 
g <- rasterGrob(reds, width = unit(1, "npc"), height = unit(1,"npc"),interpolate = TRUE) 
p <- ggplot(data = economics, aes(x = date, y = unemploy)) + 
    annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)+ 
    geom_line(alpha=1, color = "white", size = 0.5) + 
    xlab("Years") + ylab("Unemployed [thousands]") + 
    theme_base() + 
    theme(panel.background=element_blank(), 
     plot.background=element_blank(),   
     line = element_line(colour="white")) + 
    theme() 

grid.newpage() 

print(p, newpage = FALSE) 

내가 annotation_custom에서 둘의 rastergrob에 알파를 추가 할 수 있습니다. 나는 잠시 동안 찾고 있었다.

+0

숫자 값을 사용해 보셨습니까? 예 : "red"대신 "# F5262688"을 사용하십시오. – G5W

+0

음, 내 벡터의 모든 색상을 투명하게 동등하게 변환 할 수있는 "adjustcolor"함수를 찾았습니다. 감사 ! – jakzr

+0

아마도 자신의 질문에 대한 답변을 게시하여 사람들이 답변을 받았음을 알 수 있습니다. – G5W

답변

0

scales::alpha()의 목록을 투명 "알파"그리고 색상의 목록의 매개 변수를 사용하고 반환 함수 가지 AdjustColor()를 사용하는 것입니다 할 수있는 하나의 가능한 방법을 하나 개의 옵션입니다 발견 ,

grid.newpage() 
grid.text("background") 

reds <- c("brown", "red","orange","green","orange","red","brown","grey") 
grid.raster(scales::alpha(reds, 0.5), width = unit(1, "npc"), height = unit(1,"npc"),interpolate = TRUE) 
0

이 나는 ​​투명 색상