[英]R/ ggplot2/ how to move from connected points in a scatter plot to filled and transparent triangles?
以下是多維縮放實驗的x和y坐標:三種具有不同距離度量和縮放/無縮放的情況。 “Set”是指標縮放組合(1到6)。 每個案例都有一個類標簽(0或4)。
X1 X2 method scale class set
1 18.881729 -2.931111 euclidean no 0 1
2 -13.141592 -9.750710 euclidean no 4 1
3 -5.740138 12.681822 euclidean no 4 1
4 -21.886160 -15.467637 manhattan scaled 0 2
5 -16.755615 16.900148 manhattan scaled 4 2
6 38.641776 -1.432512 manhattan scaled 4 2
7 32.927820 -7.900971 minkowski no 0 3
8 -28.957697 -11.666982 minkowski no 4 3
9 -3.970123 19.567953 minkowski no 4 3
10 5.944225 25.819482 euclidean scaled 0 4
11 44.574669 -15.330675 euclidean scaled 4 4
12 -50.518894 -10.488807 euclidean scaled 4 4
13 14.287762 1.142065 manhattan no 0 5
14 -5.843410 -9.981600 manhattan no 4 5
15 -8.444351 8.839535 manhattan no 4 5
16 -24.838956 -8.194378 minkowski scaled 0 6
17 -11.435517 10.496471 minkowski scaled 4 6
18 36.274473 -2.302093 minkowski scaled 4 6
和ggplotting:
p <- ggplot(df, aes(X1, X2))
p <- p + geom_point(aes(colour = factor(scale), shape = factor(method)), size=10)
p <- p + geom_text(aes(label=class), size=5)
p <- p + geom_line(aes(X1,X2, group=factor(set)))
p <- p + theme_bw()
p
我想為每個組(“set”)制作6個填充和透明的三角形。 頂部三角形是曼哈頓 - 沒有縮放。 我使用geom_segment的實驗沒有成功,我不確定geom_polygon是否是正確的方向。 有什么建議? 謝謝!
您可以將geom_polygon
用於封閉路徑:
library(ggplot2)
p <- ggplot(df, aes(X1, X2))
p <- p + geom_polygon(aes(fill = factor(set)), alpha = .4)
p <- p + theme_bw()
p
這里, alpha
用於指定透明度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.