【发布时间】:2016-05-09 23:07:02
【问题描述】:
我想我的问题是微不足道的,但我无法弄清楚。我有一个年度数据,我想使用 ggplot2 barplot 显示。由于我第一年的酒吧太靠近 y 轴,我想扩大 x 轴的限制。但是,如果应用,我的 X 轴值会消失,甚至 theme() 规范也不会产生结果。我不明白为什么?原因可能是我使用“年”作为因素吗?但是对于条形表示,我需要使用离散比例......
谢谢!
# reproductible exemple
year<-c(2003:2010)
manag<-rep(c("A", "B"), 4)
np<-rep(c(0,1), each = 4)
val<- c(10,20,50,10,14,80,19,25)
df<-data.frame(cbind(year,
manag, np, val))
require(ggplot2)
a<-ggplot(data = df, aes(x = as.factor(year), y = val)) +
ggtitle("MISSING X VALUES!!!") +
geom_bar(stat = "identity") +
scale_x_discrete(limits= c(2002:2015))
# theme(axis.text.x=element_text(size = 8, colour = "black", angle = 90)
b<-ggplot(data = df, aes(x = as.factor(year), y = val)) +
geom_bar(stat = "identity") +
ggtitle("NOT EXPANDED X LIMITS")
grid.arrange(a, b, ncol = 2)
【问题讨论】:
标签: r ggplot2 axis-labels