2016-01-26 41 views

回答

0

可以使用plotpng

library(png) 
library(grid) 
library(ggplot2) 

img <- readPNG(system.file("img", "Rlogo.png", package="png")) 
g <- rasterGrob(img, interpolate=TRUE) 

qplot(x=sample(1:10,20,replace=TRUE), geom="blank") + 
    annotation_custom(g, xmin=4.5, xmax=5.5, ymin=3, ymax=4) + 
    geom_bar() 

也略有擴展版這表明 做到這一點 - 用陰謀 相同的例子 - 計算圖像的特定位置的位置

library(png) 
library(grid) 
library(ggplot2) 
img <- readPNG(system.file("img", "Rlogo.png", package="png")) 
g <- rasterGrob(img, interpolate=TRUE) 

p<- ggplot(data.frame(x=x), aes(x=x)) + 
    geom_bar() 

stats <- p$layers[[1]]$stat$compute_group(p$data) 

loc=5 
val=max(c(stats[stats$x==loc,]$count,0)) 
p+annotation_custom(g, xmin=loc-0.5, xmax=loc+0.5, ymin=val, ymax=val+1)+ylim(0,6) 

enter image description here

+0

qplot從哪個軟件包? – GGA

+0

'ggplot'相應地更新了代碼。 – CAFEBABE

+0

我還添加了如何從特定欄的繪圖中提取位置 – CAFEBABE

相關問題