Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one use polygon() or equivalent in lattice and ggplot2 plots?

Is it possible to annotate lattice (or ggplot2) figures with elements created with polygon() (or elements created with a similar function) from the graphics library?

I'm not too familiar with either library beyond examples of simple graphs posted on the web and printed in Deepayan Sarkar's book. Therefore, while I have code for what I've been doing in R with the graphics library, pointing me to relevant, equivalent functions and usage examples for lattice or ggplot2 specifically would be appreciated. Thanks.

like image 375
Alex Reynolds Avatar asked Nov 29 '11 01:11

Alex Reynolds


1 Answers

Here is the ggplot2 version of the first example in ?polygon()

x <- c(1:9,8:1)
y <- c(1,2*(5:3),2,-1,17,9,8,2:9)

ggplot(NULL, aes(1:10, 1:10)) + geom_point() +
  geom_polygon(aes(x, y), fill = "orange", colour = "skyblue", alpha = 0.5)

enter image description here

like image 194
kohske Avatar answered Sep 28 '22 06:09

kohske