1

I am trying to make a polygon with ggplot2 in R, but oddly it does not make a triangle (purple colour) as expected. What am I doing wrong here? This is the data:

dat = data.frame(
    V1 = c(0.11300013, 0.15496416, 0.08671747, -0.29005538, 0.05620646, 0.03683196,
        -0.04117141, -0.02807780, -0.07089467, -0.01752091),
    V2 = c(0.005029114, -0.024440967, -0.036153217, -0.019359617, 0.006836712,
        0.040843503, 0.012233072, -0.008538257, 0.008864793, 0.014684864),
    cluster = c("1", "1", "1", "2", "3", "3", "4", "4", "4", "4")
)

And here is my plotting code:

require(ggplot2)

p1 <- ggplot(data=dat, aes(x=V1, y=V2, colour=cluster)) +
    geom_polygon(data=dat, aes(x=V1, y=V2, fill=cluster), alpha=1/2) +
    geom_point(size=2) +
    theme(legend.position="none",
        axis.title.x=element_blank(),
        axis.title.y=element_blank())
plot(p1)

Finally, this is the outcoming plot: enter image description here

striatum
  • 1,428
  • 3
  • 14
  • 31

0 Answers0