【问题标题】:R: How to visualize large and clumped scatter plotR:如何可视化大而集中的散点图
【发布时间】:2014-12-11 18:37:20
【问题描述】:
 status = sample(c(0, 1), 500, replace = TRUE)
 value = rnorm(500)

 plot(value)
 smoothScatter(value)

我正在尝试绘制价值散点图,但如果我只是绘制它,数据就会全部聚集在一起,而且不是很像样。我试过smoothScatter(),它使情节看起来更好一些,但我想知道是否有办法根据相应的状态对值进行颜色编码?

我想看看地位和价值之间是否存在关系。还有什么方法可以很好地呈现数据?我尝试了箱线图,但我想知道如何使 smoothScatter() 绘图更好,或者是否有其他方法可以将其可视化。

【问题讨论】:

    标签: r graphics


    【解决方案1】:

    我假设您打算在示例中写plot(status, value)?无论如何,使用这些数据不会有太大的差异,但您应该通过以下示例了解可能需要查看的内容...

    你看过jitter吗?

    一些基础知识:

    plot(jitter(status), value)

    或者plot(jitter(status, 0.5), value)

    拥有ggplot2 套餐的鸽友你可以这样做:

    library(ggplot2)
    df <- data.frame(value, status)
    ggplot(data=df, aes(jitter(status, 0.10), value)) + 
      geom_point(alpha = 0.5)
    

    或者这个……

    ggplot(data=df, aes(factor(status), value)) +
      geom_violin()
    

    或者……

    ggplot(data=df, aes(x=status, y=value)) +
      geom_density2d() + 
      scale_x_continuous(limits=c(-1,2))
    

    或者...

    ggplot(data=df, aes(x=status, y=value)) +
      geom_density2d() +
      stat_density2d(geom="tile", aes(fill = ..density..), contour=FALSE) +
      scale_x_continuous(limits=c(-1,2))
    

    甚至这个..

    ggplot(data=df, aes(fill=factor(status), value)) +
      geom_density(alpha=0.2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-01
      • 2019-11-30
      • 2020-06-25
      • 1970-01-01
      • 2020-06-24
      • 2014-07-10
      • 1970-01-01
      • 2020-09-05
      相关资源
      最近更新 更多