如何在空间上分离不同系列的地毯 [英] How to spatially separate rug plots from different series

查看:176
本文介绍了如何在空间上分离不同系列的地毯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以图形方式评估数据集的分布(双峰型和单峰型),其中每个数据集的数据点数量可能差异很大。我的问题是使用类似地毯的方式来指示数据点的数量,但要避免出现一系列有许多数据点的问题,因为这些数据点只会出现几个点。



目前,我正在 ggplot2 中工作,结合 geom_density geom_rug 就像这样:

 #设置数据:1000 bimodalbpoints; 20个单峰a分数
set.seed(0);需要(ggplot2)
x <-c(rorm(500,mean = 10,sd = 1),rorm(500,mean = 5,sd = 1),rorm(20,mean = 7,sd = 1 ))
l < - c(rep(b,1000),rep(a,20))
d < - data.frame(x = x,l = 1)

ggplot(d,aes(x = x,color = 1))+ geom_density()+ geom_rug()



我使用<$ c攻击了一个解决方案$ c> geom_point 而不是 geom_rug

  d $ ypos < -  NA 
d $ ypos [d $ l ==b] < - 0
d $ ypos [d $ l ==a] < - 0.01

ggplot()+
geom_density(data = d,aes(x = x,color = 1))+
geom_point(data = d,aes(x = x,y = ypos,color = 1),alpha = 0.5)



然而,这并不令人满意,因为必须手动调整y位置。是否有更自动的方式来分隔不同系列的地毯,例如使用位置调整?

使用两个 geom_rug()调用 - 一个用于 b ,其他用于 a 。然后为一个 geom_rug()设置 sides =t来将它们绘制在最上面。

  ggplot(d,aes(x = x,color = 1))+ geom_density()+ 
geom_rug(data = subset(d, (x = x))+
geom_rug(data = subset(d,l ==a),aes(x = x),sides =t)


I'm trying to graphically evaluate distributions (bimodal vs. unimodal) of datasets, in which the number of datapoints per dataset can vary widely. My problem is to indicate numbers of data points, using something like rug plots, but to avoid the problem of having a series with many data points overhwelm a series with only a few points.

Currently I'm working in ggplot2, combining geom_density and geom_rug like so:

# Set up data: 1000 bimodal "b" points; 20 unimodal "a" points
set.seed(0); require(ggplot2)
x <- c(rnorm(500, mean=10, sd=1), rnorm(500, mean=5, sd=1), rnorm(20, mean=7, sd=1))
l <- c(rep("b", 1000), rep("a", 20))
d <- data.frame(x=x, l=l)

ggplot(d, aes(x=x, colour=l)) + geom_density() + geom_rug()

This almost does what I want - but the "a" points get overwhelmed by the "b" points.

I've hacked a solution using geom_point instead of geom_rug:

d$ypos <- NA
d$ypos[d$l=="b"] <- 0
d$ypos[d$l=="a"] <- 0.01

ggplot() + 
  geom_density(data=d, aes(x=x, colour=l)) +
  geom_point(data=d, aes(x=x, y=ypos, colour=l), alpha=0.5)

However this is unsatisfying because the y positions must be adjusted manually. Is there a more automatic way to separate rug plots from different series, for instance using a position adjustment?

解决方案

One way would be to use two geom_rug() calls - one for b, other for a. Then for one geom_rug() set sides="t" to plot them on top.

ggplot(d, aes(x=x, colour=l)) + geom_density() + 
  geom_rug(data=subset(d,l=="b"),aes(x=x)) +
  geom_rug(data=subset(d,l=="a"),aes(x=x),sides="t")

这篇关于如何在空间上分离不同系列的地毯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆