How can I overlay two dense scatter plots so that I can see the outlines of each in R or Matlab?

前端 未结 4 677
清歌不尽
清歌不尽 2021-02-13 16:40

See this example\"Example

This was created in matlab by making two scatter plots indepe

4条回答
  •  悲&欢浪女
    2021-02-13 17:12

    Using ggplot2 you can add together two geom_point's and make them transparent using the alpha parameter. ggplot2 als adds up transparency, and I think this is what you want. This should work, although I haven't run this.

    dat = data.frame(x = runif(1000), y = runif(1000), cat = rep(c("A","B"), each = 500))
    ggplot(aes(x = x, y = y, color = cat), data = dat) + geom_point(alpha = 0.3)
    

    ggplot2 is awesome!

    This is an example of calculating and drawing a convex hull:

    library(automap)
    library(ggplot2)
    library(plyr)
    loadMeuse()
    theme_set(theme_bw())
    
    meuse = as.data.frame(meuse)
    chull_per_soil = ddply(meuse, .(soil), 
               function(sub) sub[chull(sub$x, sub$y),c("x","y")])
    
    ggplot(aes(x = x, y = y), data = meuse) +
      geom_point(aes(size = log(zinc), color = ffreq)) +
      geom_polygon(aes(color = soil), data = chull_per_soil, fill = NA) +
      coord_equal()
    

    which leads to the following illustration:

    enter image description here

提交回复
热议问题