add axis ticks and labels in ggplot2 r

Here is data.

X <- 1:10
Y <- rnorm (length(X), 5, 2)
ticks <- data.frame (t = c(5, 8, 9), l = c(1:3)) 

plot (X, Y, xaxt = "n")

axis(1, at = ticks$t, labels = ticks$l)

I want to do similar job in ggplot2. How can I do it

Answers


library(ggplot2)

X <- 1:10
Y <- rnorm (length(X), 5, 2)
ticks <- data.frame (t = c(5, 8, 9), l = c(1:3))

df <- data.frame(X, Y)


p <- ggplot(data=df, aes(x = X,y = Y) )
p <- p + scale_x_continuous(breaks=c(ticks$t), 
                            labels=c(ticks$l))
p <- p + geom_point()
p <- p + theme_bw()
p

Hope this helps.


Need Your Help

how to make readonly property in knockout

knockout.js knockout-2.0

I am using knockout and i am quiet new to it , i have a certain condition in which i have to define some read only properties in my model .

Timer and TimerTask Java

java timer timertask

I want my program to print Hello User, a ten seconds later print Ten Seconds Have Gone By, finally, a few seconds later print Goodbye User. I just don't know what or how to start to do this. Thanks...