2012-05-07 6 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

관련 문제