¿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():

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

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 ?

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

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.