如何克服ggplot2中无抖动或透明度的重叠点 [英] How does one overcome overlapping points without jitter or transparency in ggplot2

查看:123
本文介绍了如何克服ggplot2中无抖动或透明度的重叠点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用ggplot2。我有一些小的n(大约30左右)粒子数据,有很多重叠。无论是抖动还是Alpha(透明度)都不适合。相反,带有堆栈和偏移量的带状图可以做到最好,但我不知道如何在ggplot2中做到这一点。你知道吗?



要查看最终结果应该点击这个 graphic



这是我几年前使用的脚本。 b
$ b

  stripchart(SystData $ DayTo1Syst〜SystData $ strain,vertical = TRUE,method =stack,pch = 19,offset = .3,xlab = Strain,main =系统性疾病发作的快速性,ylab =接种后的天数)


 #您的数据
df < - data.frame(gp = rep(LETTERS [1:5],each = 8) ,y = sample(1:4,40,replace = TRUE))
#计算偏移量
df < - ddply(df,。(y,gp),transform,offset =(1:长度(gp)-1)/ 20)
qplot(gp,y,data = df)+ stat_identity(aes(as.numeric(gp)+ offset))+ theme_bw()


I am starting to use ggplot2. I have some small n (about 30 or so) granular data with lots of overlap. Neither jitter nor alpha (transparency) are suitable. Instead a stripchart with stack and offset do it best but I do not know how to do it in ggplot2. Do you know?

To see what the end result should be click on this graphic.

Here is the script I used a few years ago.

stripchart(SystData$DayTo1Syst~SystData$strain,vertical=TRUE,method="stack",pch=19,offset=.3,xlab="Strain",main="Rapidity of Systemic Disease Onset",ylab="Days post inoculation")

解决方案

# your data
df <- data.frame(gp = rep(LETTERS[1:5], each =8), y = sample(1:4,40,replace=TRUE))
# calculate offsets
df <- ddply(df, .(y, gp), transform, offset = (1:length(gp)-1)/20)
qplot(gp, y, data=df) + stat_identity(aes(as.numeric(gp)+offset)) + theme_bw() 

这篇关于如何克服ggplot2中无抖动或透明度的重叠点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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