gpt4 book ai didi

r - 抖动 geom_line()

转载 作者:行者123 更新时间:2023-12-03 13:16:42 26 4
gpt4 key购买 nike

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

请参阅下面的代码,
jitter geom_line

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)

最佳答案

你可以试试

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

看看这是否有效。

关于r - 抖动 geom_line(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10866047/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com