【问题标题】:Cleaning up density plots in R清理 R 中的密度图
【发布时间】:2017-04-18 21:14:35
【问题描述】:

我想在这里平滑我的图表的边缘。有没有办法让geom_density2d 和/或stat_density2d 进行一些不同的插值以消除这些明显的不连续性?

我用它来创建包含的示例:

  ggplot(data = PlotModel1, aes(x = Lon, y = Lat)) +
  geom_point(aes(color = Conc), shape = "") +
  stat_density2d(aes(fill = ..level..), n = 100, geom="polygon", contour = TRUE) +
  guides(fill = FALSE) +
  theme_bw()

我想要这样一个更流畅的情节

谢谢!

【问题讨论】:

  • 请您提供一些数据,以便重现您的问题

标签: r ggplot2 heatmap


【解决方案1】:

这个问题在这里得到解答: non-overlapping polygons in ggplot density2d

基本上,您可以扩展 x,y 限制以允许完全绘制多边形。

然后,如果这使绘图过于缩小,您可以使用 coord_cartesian 设置限制:

r stat_contour incorrect fill with polygon

因此,对于您的代码,它将类似于:

  ggplot(data = PlotModel1, aes(x = Lon, y = Lat)) +
  geom_point(aes(color = Conc), shape = "") +
  stat_density2d(aes(fill = ..level..), n = 100, geom="polygon", contour = TRUE)+
  guides(fill = FALSE) +
  theme_bw()+
  xlim(-150, -50)+
  ylim(30, 45)+
  coord_cartesian(xlim=c(-110, -80),ylim=c(33, 41))

【讨论】:

    猜你喜欢
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 2013-05-19
    • 1970-01-01
    相关资源
    最近更新 更多