抖动geom_line() [英] jitter geom_line()

查看:128
本文介绍了抖动geom_line()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法抖动 geom_line()中的行?我知道这有点违背了这个情节的目的,但是如果你有一个只有几行的情节,并且希望他们都表明它可能会很方便。也许有其他解决方案来解决这个可见性问题。



请参阅下面的代码,

  A <-c(1 ,2,3,5,1)
B < - c(3,4,1,2,3)
id < - 1:5
df < - 数据。 frame(id,A,B)


#install.packages(reshape2)
require(reshape2)#for melt
dfm< - melt(df, id = c(id))

#install.packages(ggplot2)
require(ggplot2)
p1 < - ggplot(data = dfm,aes(x =变量,y = value,group = id,
color = as.factor(id)))+ geom_line()+ labs(x =id#1几乎不是
,因为它被id #5)+ scale_colour_manual(值=
c('红','蓝','绿','黄','黑'))


p2 < - ggplot(subset(dfm,id!= 5),aes(x = variable,y = value,
group = id,color = as.factor(id)))+ geom_line()+ labs(x = id#
5已删除,id#1可见)+ scale_colour_manual(va lues =
c('red','blue','green','yellow','black'))

#install.packages(RODBC)
require(gridExtra )

grid.arrange(p1,p2)


解决方案您可以尝试

  geom_line(position = position_jitter(w = 0.02,h = 0))

,看看效果如何。


Is there a way to jitter the lines in geom_line()? I know it kinda defies the purpose of this plot, but if you have a plot with few lines and would like them all to show it could be handy. Maybe some other solution to this visibility problem.

Please see below for code,

A  <- c(1,2,3,5,1)
B  <- c(3,4,1,2,3)
id <- 1:5
df <- data.frame(id, A, B)


# install.packages(reshape2)
require(reshape2) # for melt
dfm <- melt(df, id=c("id"))

# install.packages(ggplot2)
require(ggplot2)
p1 <- ggplot(data = dfm, aes(x = variable, y = value, group = id, 
color= as.factor(id))) + geom_line() + labs(x = "id # 1 is hardly 
visible as it is covered by id # 5") + scale_colour_manual(values = 
c('red','blue', 'green', 'yellow', 'black')) 


p2 <- ggplot(subset(dfm, id != 5), aes(x = variable, y = value, 
group = id, color= as.factor(id))) + geom_line() + labs(x = "id # 
5 removed, id # 1 is visible") + scale_colour_manual(values = 
c('red','blue', 'green', 'yellow', 'black')) 

# install.packages(RODBC)
require(gridExtra)

grid.arrange(p1, p2)

解决方案

You can try

geom_line(position=position_jitter(w=0.02, h=0))

and see if that works well.

这篇关于抖动geom_line()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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