BioMan
BioMan

Reputation: 704

geom_segment combined with geom_point

I am plotting a geom_point in ggplot and I want to combine it with a segment from the x-asis to the point. How do I specify that the segment should go from the x-axis?

 head(pValues_Both.m)

  value
1 5.502
2 0.823
3 0.374
4 3.886
5 0.724
6 0.706

ggplot(pValues_Both.m, aes(x=seq_along(value),y=value)) +   geom_segment(aes(yend=value), xend=0, colour="grey50") +
  geom_point(size=3.5,colour="#2E64FE")

Upvotes: 0

Views: 934

Answers (1)

Didzis Elferts
Didzis Elferts

Reputation: 98449

You should use seq_along(value) also as the xend= value inside aes() of geom_segment().

ggplot(pValues_Both.m, aes(x=seq_along(value),y=value)) +   
      geom_point(size=3.5,colour="#2E64FE")+
      geom_segment(aes(yend=0,xend=seq_along(value)), colour="grey50")

Upvotes: 1

Related Questions