【问题标题】:Plot the convex hull in FDA plot - R在 FDA 图中绘制凸包 - R
【发布时间】:2020-12-20 12:51:34
【问题描述】:

我正在尝试使用 ggpubr 包为该图中的每个组添加一个凸包?为什么它不起作用?

代码:

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)  

【问题讨论】:

    标签: r ggplot2 ggpubr


    【解决方案1】:

    你还没有告诉stat_chull x 和 y 点在哪里。您告诉geom_point 它们在哪里,但是当您将它们添加到绘图时,geoms 和 stats 不会相互继承。您可以将 x 和 y 坐标添加到 stat_chull,或者更好的是,将它们添加到 ggplot 调用中。 那么stat_chull可以继承它们,并且你可以节省一些打字。

    顺便说一句,您使用了library 调用 dplyr、MASS、scales 和 data.table,这些在本示例中不需要,但您忘记为 mda 调用库, /em> 需要:

    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) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-13
      • 2017-04-29
      • 2015-06-01
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      • 1970-01-01
      • 2018-06-23
      相关资源
      最近更新 更多