我的数据帧称为Finalcombined看起来是这样的: 我有以下图表:
而下面的代码:
Labourproductivity<- ggplot(Finalcombined, aes(x = quarter, y = LabourProductivity, group=1))+geom_line(colour="black", size=0.5) +
labs(x="Time", y=("Labour Productivity"))+
theme(axis.text.x = element_text(angle = 90, hjust = 1, ))+
geom_point(colour="black", size=2, shape=16)+
geom_smooth(aes(group=1))+
theme(axis.text=element_text(size=13),axis.title=element_text(size=16,face="bold"))+
theme(panel.grid.major = element_line(colour = "white", size=0.50),panel.grid.minor = element_line(colour = "white", size=0.16))
Labourproductivity
我的问题是如何能够摆脱一些关于x轴的值,但仍具有相同的图形。 我只想包括(2004年第一季度,2005年第一季度,2006年第一季度)等。 我将如何去吗? 谢谢您的帮助!
下面添加到您的ggplot
scale_x_discrete(breaks=Finalcombined$quarter[grepl("Q1",Finalcombined$quarter)])
例:
require("ggplot2")
#dummy data
Q <- paste(sort(rep(2004:2013,4)),paste0("Q",1:4))
Finalcombined <-
data.frame(quarter= Q,
LabourProductivity=runif(length(Q)))
#plot
ggplot(Finalcombined,
aes(x = quarter,
y = LabourProductivity,
group=1)) +
geom_line(colour="black", size=0.5) +
labs(x="Time", y=("Labour Productivity")) +
theme(axis.text.x = element_text(angle = 90, hjust = 1, )) +
geom_point(colour="black", size=2, shape=16) +
geom_smooth(aes(group=1)) +
theme(axis.text=element_text(size=13),axis.title=element_text(size=16,face="bold")) +
theme(panel.grid.major = element_line(colour = "white", size=0.50),panel.grid.minor = element_line(colour = "white", size=0.16)) +
#change X axis labels
scale_x_discrete(breaks=Finalcombined$quarter[grepl("Q1",Finalcombined$quarter)])