我很努力使日期格式正確。數據已經處於熔化()格式。發生共享相同數據的數據中有四個變量。我只想繪製一個簡單的線形圖,其中包含四行(每個變量作爲一條不連續的行)並將Sep-12顯示爲最新的數據點?我正在使用舊的ggplot。隨意我有兩個問題。如何在折線圖中以Sep-12格式顯示數據並抑制網格線和灰色背景?
第一個問題:如何按季度顯示數據(日期間隔爲Sep-11,Dec-11, Mar-12,Jun-12和Sep-12)?
第二個問題:如何抑制網格線和灰色背景?
x4.1.m<-structure(list(Var.1=structure(c(1L,2L,3L,4L,5L,6L,1L,2L,3L,4L,5L,6L,1L,2L,3L,4L,5L,6L,1L,2L,3L,4L,5L,6L,1L,2L,3L,4L,5L,6L),.Label=c("I'vechangedforwork/anewjob/goneonaworkplan","Iwantaphonethat2degreesdoesn'toffer","IwantBestMates/Favourites","Iwasofferedorsawabetterofferonanothernetwork","Issueswiththe2degreesnetwork(poorcoverage)","Other"),class="factor"),YearQuarter=structure(c(1L,1L,1L,1L,1L,1L,2L,2L,2L,2L,2L,2L,3L,3L,3L,3L,3L,3L,4L,4L,4L,4L,4L,4L,5L,5L,5L,5L,5L,5L),.Label=c("2011-09-01","2011-12-01","2012-03-01","2012-06-01","2012-09-01"),class="factor"),value=c(0.23,0.23,0.121,0.25,0.223,0.14,0.39,0.22,0.05,0.37,0.25,0.2,0.09,0.14,0.05,0.3,0.4,0.12,0.13,0.1,0.26,0.38,0.28,0.15,0.33,0.05,0.06,0.44,0.32,0.43)),.Names=c("Var.1","YearQuarter","value"),row.names=c(NA,-30L),class="data.frame")
x4.1.m$YearQuarter <- format(as.Date(x4.1.m$YearQuarter),"%b-%y")
x4.line <- ggplot(data=x4.1.m, aes(x=factor(YearQuarter), y=value,colour=Var.1)) +
geom_smooth(se=F, size=1.5)+labs(y="Percentage",x="Year Quarter")
x4.line+geom_text(aes(label =paste(round(value*100,0), "%", sep=""),group=Var.1),
size = 3, hjust = 0.5, vjust =1.5) +
opts(axis.line = theme_segment(colour = "black"),
panel.grid.major = theme_blank(),
panel.background=theme_blank(),
panel.grid.minor = theme_blank(),
panel.border = theme_blank()) +
scale_y_continuous("Percentage",labels=percent, limits=c(0,0.5)) +
ggtitle("Percentages:Main Reasons for Leaving 2degrees by Quarter") +
theme(plot.title = element_text(size=rel(1.2)))
您正在使用哪個GGPLOT2的版本? – agstudy
目前尚不清楚你試圖繪製的四個變量是哪一個? YQ Sep'11 - Sep '12? Var.1? –