【问题标题】:How to plot countours around points with different alpha level of countours如何绘制具有不同 alpha 等高线水平的点周围的等高线
【发布时间】:2023-02-04 20:52:05
【问题描述】:

我想用 Petal.Length (x) 和 Sepal.Length (y) 在训练 iris 数据集上重现附加图。我认为这是关于 stat_density_2d 参数,但我无法获得完全相同的图片。 非常感谢任何帮助。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您需要将 alpha 映射到 stat_density2d_filled 中计算出的 level,并调整 breaks 参数以适应:

    library(ggplot2)
    
    ggplot(iris, aes(Petal.Length, Sepal.Length, fill = Species)) +
      stat_density2d_filled(aes(alpha = after_stat(level)),
                            h = c(1, 1), breaks = c(0, 0.1, 0.2, 0.3, 0.4, 5)) +
      geom_point(shape = 21, size = 3) +
      scale_alpha_manual(values = seq(0, 1, length = 6)) +
      theme_minimal(base_size = 16) +
      theme(legend.position = "none")
    

    【讨论】:

      猜你喜欢
      • 2019-12-13
      • 2020-09-25
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-23
      • 1970-01-01
      相关资源
      最近更新 更多