fork download
  1. rm(list=ls())
  2.  
  3. require(ggplot2)
  4. require(sp)
  5.  
  6. set.seed(123456)
  7. df=data.frame(x=runif(100,-1,1)
  8. ,y=runif(100,-1,1))
  9. x=seq(-1,1,length=21)
  10. Line1=data.frame(x=x,y=-0.5+0.8*x,g="L1")
  11. Line2=data.frame(x=rev(x),y=0.5+0.6*rev(x),g="L2")
  12. Linedf=rbind(Line1,Line2)
  13. df$in.pg = ifelse(as.logical(point.in.polygon(df$x, df$y, pol.x=Linedf$x, pol.y=Linedf$y))
  14. ,"Yes","No")
  15. head(df)
  16. ggplot()+
  17. geom_point(aes(x=x,y=y,colour=in.pg),data=df,inherit.aes = F)+
  18. geom_path(aes(x=x,y=y,group=g,colour=g),size=1.2,data=Linedf,inherit.aes = F)
  19.  
Success #stdin #stdout #stderr 0.95s 68492KB
stdin
Standard input is empty
stdout
           x           y in.pg
1  0.5955686 -0.92289262    No
2  0.5071302  0.31889504   Yes
3 -0.2174886 -0.37706295   Yes
4 -0.3168866 -0.62086170   Yes
5 -0.2774118  0.25214263   Yes
6 -0.6033105  0.03343692   Yes
stderr
Loading required package: ggplot2
Loading required package: sp