How to build a comb?

This type of plot may have a different name, if you so kindly point me to the appropriate post.

I am trying to build a simple "comb" chart with 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

There seem to be so many lines of code for a simple plot, is there any other function ggplotI am missing?

0
source share
1 answer

I don't know about ggplot, but why not use it graphics::rug?

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

enter image description here

+1
source

Source: https://habr.com/ru/post/1599290/


All Articles