我正在尝试在ggplot2
中使用R
创建一个多边形,但奇怪的是它没有按预期形成三角形(紫色)。我在这做错了什么?这是数据:
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")
)
这是我的密谋代码:
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)