-1

my data is something like this:

A   B   C
a   1   5
b   2   6 
c   3   7
d   4   8 

So i would like get a plot something like this : PLot

j <- ggplot(data = data,
        aes(A, B)) +
        theme_classic() +
        geom_point( size=3, color="black") +
        scale_y_continuous(trans = "log10") +
        geom_segment(aes(xend=A, yend=0))

My plot using segments is A vs B, I would like to add another plot to the same graph, A vs C, with geom_segment. And don't worry about horizontal line, is just 2 means, it's no in the code for simplify

  • Please take a look at how to make a [great reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Martin Gal Jul 11 '21 at 21:57
  • The data doesn't give information on where to draw the horizontal lines. – Rui Barradas Jul 11 '21 at 22:14

1 Answers1

2

Here is a way. Draw two geom_segment's, the longer and thiner first. Then the points.
Note that the data in the question doesn't give information on where to draw the horizontal lines.

library(ggplot2)

ggplot(data, aes(A)) +
  geom_segment(aes(xend = A, y = 0, yend = C)) +
  geom_segment(aes(xend = A, y = 0, yend = B), color = "red", size = 2) +
  geom_point(aes(y = C), size = 2)

enter image description here


Data

data <- data.frame(A = letters[1:4], B = 1:4, C = 5:8)
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66