¿Cómo trazar un peine?

This type of plot might have a different name, if so kindly point me to a relevant post.

I am trying to plot simple "comb" plot using geom_segment():


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

#plot comb
       aes(x=x,y=0,xend=x, yend=10)) +
  geom_segment() +
        axis.title.x=element_blank()) +
  #hide y ticks and label
  scale_y_continuous(breaks=NULL) +

enter image description here

It seems, so many lines of code for a simple plot, is there other ggplot function I am missing?

preguntado el 12 de junio de 14 a las 10:06

Your plot really only has one line of code, the rest is defining a new theme. The only suggestion I have is to use geom_vline en lugar de geom_segment. Intentar: ggplot(dat, aes(x=x, y=0)) + geom_blank() + geom_vline(aes(xintercept=x), data=dat) -

Pensé en usar geom_vline, too. Then I have to use geom_blank and still have to hide y ticks and labels. -

1 Respuestas

Dunno about ggplot, but why not use graphics::rug ?

dat <- sample(1:100,20)

enter image description here

Respondido el 12 de junio de 14 a las 12:06

+1 Rug is the word I was looking for. There is geom_rug, but I can't change the height. Sorry, it has to be ggplot solución. - zx8754

No soy un ggplot expert but I wouldn't be surprised to find there's some aesthetic or parameter that can be passed via ... to change the tic-mark height. - Carlos Witthoft

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.