Show specific x-axis value on ggplot

Im creating ggplot

s geom_vline

at a specific location on the x axis. i would like the x axis to show that the specific value

Below is my details + code:

dput(agg_data)
structure(list(latency = structure(c(0, 1, 2, 3, 4, 5, 6, 7, 
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 24, 26, 28, 
29, 32, 36, 37, 40, 43, 46, 47, 48, 49, 54, 64, 71, 72, 75, 87, 
88, 89, 93, 134, 151), class = "difftime", units = "days"), count = c(362, 
11, 8, 5, 4, 2, 8, 6, 4, 2, 2, 1, 5, 1, 2, 2, 2, 1, 1, 1, 2, 
1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 
1, 1, 1), cum_sum = c(362, 373, 381, 386, 390, 392, 400, 406, 
410, 412, 414, 415, 420, 421, 423, 425, 427, 428, 429, 430, 432, 
433, 435, 436, 437, 438, 439, 440, 441, 442, 444, 446, 447, 448, 
449, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460), cum_dist = c(0.78695652173913, 
0.810869565217391, 0.828260869565217, 0.839130434782609, 0.847826086956522, 
0.852173913043478, 0.869565217391304, 0.882608695652174, 0.891304347826087, 
0.895652173913044, 0.9, 0.902173913043478, 0.91304347826087, 
0.915217391304348, 0.919565217391304, 0.923913043478261, 0.928260869565217, 
0.930434782608696, 0.932608695652174, 0.934782608695652, 0.939130434782609, 
0.941304347826087, 0.945652173913043, 0.947826086956522, 0.95, 
0.952173913043478, 0.954347826086957, 0.956521739130435, 0.958695652173913, 
0.960869565217391, 0.965217391304348, 0.969565217391304, 0.971739130434783, 
0.973913043478261, 0.976086956521739, 0.980434782608696, 0.982608695652174, 
0.984782608695652, 0.98695652173913, 0.989130434782609, 0.991304347826087, 
0.993478260869565, 0.995652173913044, 0.997826086956522, 1)), .Names = c("latency", 
"count", "cum_sum", "cum_dist"), row.names = c(NA, -45L), class = "data.frame")

      

and the code:

library(ggplot2)
library(ggthemes)
    russ<-ggplot(data=agg_data,aes(x=as.numeric(latency),y=cum_dist))+geom_line(size=2)
    russ<-russ+ggtitle("Latency from first click to Qualified Demo:") + xlab("in Days")+ ylab("Proportion of maturity")+theme_economist()
    russ<-russ+geom_vline(aes(xintercept=10), color="black", linetype="dashed")
    russ

      

which creates the following graph: enter image description here

I want the graph to display the value "10" (same place as vline) on the x-axis

I've looked for some other similar answers, for example in Customize Axis Labels but this one creates x (s scale_x_discrete

) axis labels and doesn't add a new number to the current scale, which is more than what they need.

Thanks in advance!

+3


source to share


1 answer


In your case, the x scale is continuous, so you can use the function scale_x_continuous()

and provide breaks at the positions you want.



russ + scale_x_continuous(breaks=c(0,10,50,100,150))

      

+10


source







All Articles