如何绘制梳子?

时间:2014-06-12 09:18:44

标签: r ggplot2

这种类型的情节可能有不同的名称,如果这样请将我指向相关的帖子。

我试图使用geom_segment()绘制简单的“梳子”图:

require(ggplot2)

#dummy data
set.seed(1)
dat <- data.frame(x=sample(1:100,20))

#plot comb
ggplot(data=dat,
       aes(x=x,y=0,xend=x, yend=10)) +
  geom_segment() +
  theme(panel.grid.major.x=element_blank(),
        panel.grid.minor.x=element_blank(),
        axis.title.x=element_blank()) +
  #hide y ticks and label
  scale_y_continuous(breaks=NULL) +
  ylab(NULL)

enter image description here

看起来,对于一个简单的情节来说,这么多代码行还有其他ggplot函数我不知道了吗?

1 个答案:

答案 0 :(得分:1)

Dunno关于ggplot,但为什么不使用graphics::rug

set.seed(1)
dat <- sample(1:100,20)
plot(dat,dat,t='n')
rug(dat)

enter image description here