【发布时间】:2019-03-30 17:21:14
【问题描述】:
我正在尝试根据使用 geom_point 切割成间隔/组的值在 ggplot 中添加省略号(来自 Pkg vegan 中的排序)。我认为如果我提供一个使用 iris 数据的示例会更容易:
data("iris")
T <- metaMDS(iris[1:4]) #perform an ordination with the package vegan
ScIris <- as.data.frame(scores(T)) #extract the values for plotting
RandomNumbers <- runif(150, 1, 100) #generate metaData used for colors
ScIris$test_stat <- RandomNumbers
下面的代码生成了正确着色的点图,但只在所有点周围添加了一个椭圆。
ggplot(ScIris, aes(NMDS1, NMDS2)) +
geom_point(aes(colour = cut(test_stat, c(0, 25, 50, 75, 85,95, 99, 100))),
size = 5) +
stat_ellipse() +
scale_color_manual(name = "proportions",
values = c("(0,25]" = "black",
"(25,50]" = "dark green",
"(50,75]" = "green",
"(75,85]" = "yellow",
"(85,95]" = "orange",
"(95,99]" = "purple",
"(99,100]" = "blue",
labels = c("0", "25", "50", "75", "85", "95","<100")))
基于这篇文章ggplot2 draw individual ellipses but color by group 我尝试修改 stat_ellipse 参数,但没有任何东西可以正确绘制。
stat_ellipse(aes(x=NMDS1, y=NMDS2, colour = cut(test_stat, c(0, 25, 50, 75, 85,95, 99, 100), group=cut(test_stat, c(0, 25, 50, 75, 85,95, 99, 100)),type = "norm"))
如何为每个分组/剪切组添加椭圆?因此,黑色椭圆表示 0-25 之间的点,蓝色椭圆表示 99-100 等。ggplot 很棒,但学习曲线陡峭。
【问题讨论】: