【问题标题】:Rectangular ggplot2 geom_point shape矩形 ggplot2 geom_point 形状
【发布时间】:2016-02-19 01:44:44
【问题描述】:

我遇到了this question,它有一个非常酷的图表。我对左侧的图表感兴趣,其中包含随时间变化的矩形点。

这些矩形点不是 R 提供 geom_point() 命令的默认点集的一部分。虽然我可以重现图表(或至少一个非常相似的图表),但我不知道如何让这些点看起来像那样。

我怎样才能做到这一点?

【问题讨论】:

    标签: r graph ggplot2


    【解决方案1】:

    在我看来,这只是geom_tile,而不是目标图中的geom_point。

    require("ggplot2")
    
    ggplot(iris) + geom_tile(aes(x = Sepal.Length, y = Sepal.Width, 
                                 fill = Petal.Length), color = "white") + 
      facet_grid(Species ~ .) + 
      scale_fill_gradient(low = "red3", high = "blue4")
    

    【讨论】:

      【解决方案2】:

      虽然不完全符合您的要求,但您可以使用 scale_shape_manual() 即更改绘图形状

      d <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species, shape = Species))
      d <- d + geom_point()
      d + scale_shape_manual(values = c(15, 15, 15))
      

      【讨论】:

      • 谢谢,但scale_shape_manual() 允许您设置 ggplot 中使用的形状序列,但不能引入新形状(或更改现有形状),这是我相信我正在寻找的。​​span >
      【解决方案3】:

      你应该可以用 geom_rect 做到这一点:

      library(ggplot2)
      df <- data.frame(x = c(1,2,3), y = c(1,2,1), type = c("a","b","c"))
      ggplot(df) +
        geom_rect(aes(xmin = x, ymin = y, xmax = x + 0.3, ymax = y + 0.6, fill = type))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多