¿Cómo trazar un peine?
Frecuentes
Visto 685 equipos
0
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)
It seems, so many lines of code for a simple plot, is there other ggplot
function I am missing?
1 Respuestas
1
Dunno about ggplot, but why not use graphics::rug
?
set.seed(1)
dat <- sample(1:100,20)
plot(dat,dat,t='n')
rug(dat)
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 r ggplot2 or haz tu propia pregunta.
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 degeom_segment
. Intentar:ggplot(dat, aes(x=x, y=0)) + geom_blank() + geom_vline(aes(xintercept=x), data=dat)
- AndriePensé en usar
geom_vline
, too. Then I have to usegeom_blank
and still have to hidey
ticks and labels. - zx8754