[英]add axis ticks and labels in 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中做類似的工作。 我該怎么做
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
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.