我希望这有帮助。如果旋转轴不起作用,那么您可以使用breaks
and手动设置轴labels
的中断和标签,scale_x_continuous
如下所示:
require(ggplot2)
# dummy data
set.seed(45)
len <- 50
df <- data.frame(years = factor(seq(1901, 1950, length.out = len)),
values = 1e6 * runif(len), group=factor(rep(1:5, each=len/5)))
p <- ggplot(data = df, aes(x = years, fill=group)) + geom_bar(aes(weight = values))
require(scales) # for removing scientific notation
p <- p + scale_y_continuous(labels = comma)
# manually generate breaks/labels
labels <- seq(1901, 2000, length.out=10)
# and set breaks and labels
p <- p + scale_x_discrete(breaks=labels, labels=as.character(labels))
p