Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show a specific value of x-axis on ggplot

Tags:

r

ggplot2

Im creating a ggplot with geom_vline at a specific location on the x axis. i would like the x axis to show that specific value

Following is my data + 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 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 plot: enter image description here

I want the plot show the value '10' (same location as the vline) on the x-axis

I looked for some other similar answers, like in Customize axis labels but this one re creates the x axis labels (with scale_x_discrete), and does not add a new number to the current scale, which is more of what im looking for.

thanks in advance!

like image 397
Yehoshaphat Schellekens Avatar asked Dec 12 '22 03:12

Yehoshaphat Schellekens


1 Answers

In your case x scale is continuous, so you can use function scale_x_continuous() and provide breaks at positions you need.

russ + scale_x_continuous(breaks=c(0,10,50,100,150))
like image 178
Didzis Elferts Avatar answered Jan 26 '23 00:01

Didzis Elferts