[英]Plot the convex hull in FDA plot - R
我正在尝试使用 ggpubr package 为这个 plot 中的每个组添加一个凸包? 为什么它不起作用?
代码:
library(dplyr)
library(MASS)
library(ggplot2)
library(scales)
library(ggpubr)
library(data.table)
irisfda <- fda(Species ~ ., data = iris, method = mars)
df1 <- cbind(data.frame(irisfda$fit$fitted.values), species = iris[,"Species"])
ggplot(df1) +
geom_point(aes(X1, X2, color = species, shape = species), size = 2.5) +
labs(x = "FDA1",y = "FDA1") +
stat_chull(aes(color = species, fill = species), geom = "polygon", alpha = 0.1)
您还没有告诉stat_chull
x 和 y 点在哪里。 你告诉geom_point
它们在哪里,但是当你将它们添加到 plot 时,geoms 和 stats 不会相互继承。你可以将 x 和 y 坐标添加到stat_chull
或者,更好的是,将它们添加到ggplot
称呼。 然后stat_chull
可以继承它们,您可以节省一些输入。
顺便说一下,您使用了 dplyr、MASS、比例和 data.table 的library
调用,这些在本例中是不需要的,但是您忘记了对mda
的库调用,这是需要的:
library(ggplot2)
library(ggpubr)
library(mda)
irisfda <- fda(Species ~ ., data = iris, method = mars)
df1 <- cbind(data.frame(irisfda$fit$fitted.values), species = iris[,"Species"])
ggplot(df1, aes(x = X1, y = X2, color = species, shape = species)) +
geom_point(size = 2.5) +
labs(x = "FDA1",y = "FDA1") +
stat_chull(geom = "polygon", alpha = 0.1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.