如何在ggplot2中绘制带有重复x轴标签的折线图
How to plot line graph with repetitive x axis lables in ggplot2
我有一个数据集,其中 x 轴标签不唯一且非数字。这是一个示例:
0 )
0 )
0 .
0 )
1 )
420 )
474 )
518 )
567 )
580 )
当我使用这段代码用 ggplot2 绘制它时:
ggplot(data=Figure3b, aes(x=Bracket, y=Counts)) + geom_line()
我明白了:
而我正在寻找这样的东西:
据我所知,它以某种方式将所有具有相同 x 轴标签的值分组,而我希望它只按顺序绘制点。
为您的 parens 分配索引,然后绘制
dat$index <- 1:nrow(dat)
ggplot(dat, aes(index, x)) + geom_line(lwd=2, col="blue") +
scale_x_discrete(labels=dat$y) + xlab("brackets")
数据看起来像:
> head(dat)
# x y index
# 1 0 ) 1
# 2 0 . 2
# 3 0 ) 3
# 4 1 ) 4
# 5 420 ) 5
# 6 474 ) 6
我有一个数据集,其中 x 轴标签不唯一且非数字。这是一个示例:
0 )
0 )
0 .
0 )
1 )
420 )
474 )
518 )
567 )
580 )
当我使用这段代码用 ggplot2 绘制它时:
ggplot(data=Figure3b, aes(x=Bracket, y=Counts)) + geom_line()
我明白了:
而我正在寻找这样的东西:
据我所知,它以某种方式将所有具有相同 x 轴标签的值分组,而我希望它只按顺序绘制点。
为您的 parens 分配索引,然后绘制
dat$index <- 1:nrow(dat)
ggplot(dat, aes(index, x)) + geom_line(lwd=2, col="blue") +
scale_x_discrete(labels=dat$y) + xlab("brackets")
数据看起来像:
> head(dat)
# x y index
# 1 0 ) 1
# 2 0 . 2
# 3 0 ) 3
# 4 1 ) 4
# 5 420 ) 5
# 6 474 ) 6