2012-05-07 15 views
4

ここはデータです。ggplot2に軸のティックとラベルを追加するr

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) 

ggplot2で同様の作業をしたいと思います。私はそれをどのように行うことができます

enter image description here

答えて

13
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 

は、この情報がお役に立てば幸いです。

axis labels and breaks demo ggplot2