Is there a way to limit vline lengths in ggplot2

前端 未结 1 1203
面向向阳花
面向向阳花 2021-02-20 05:55

I\'m trying to show an intercept on a line graph using the ggplot vline and hline but want the lines to cease at the point of interception on the graph. Is this possible either

相关标签:
1条回答
  • 2021-02-20 06:15

    Expanding the comment by @joran into an answer and example

    geom_vline draws the whole way across the plot; that is its purpose. geom_segment will only draw between specific end points. It helps to make a data frame with the relevant information for drawing the lines.

    probs <- c(0.25, 0.50, 0.75)
    marks <- data.frame(probability = probs,
                        number = sapply(probs, qbirthday, classes=365, coincident=3))
    

    With this, making the lines only go to the intersection is easier.

    qplot(number,probability,data=subset(pshare,probability<0.99)) +
      geom_segment(data=marks, aes(xend=-Inf, yend=probability)) +
      geom_segment(data=marks, aes(xend=number, yend=-Inf))
    

    enter image description here

    0 讨论(0)
提交回复
热议问题