我不確定ggplot中的默認日期間隔是多少。我的數據有五個數據點,包括2011年9月,2011年12月,2012年3月,2012年6月和2012年9月。如何更改ggplot中的默認日期間隔?
ggplot從我的數據顯示不同的數據點,我發現有點討厭。我錯過了什麼?
你能幫顯示「月2011年,DEC-2011,MAR-2012,君2012年九月,2012
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","IwantaphonethatVodafonedoesn'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")
library(scales)
library(ggplot2)
###data
x4.1.m$YearQuarter <- as.Date(x4.1.m$YearQuarter)
x4.1.m$label <- paste(round(x4.1.m$value*100,0), "%", sep="")
### plot
x4.line <- ggplot(data=x4.1.m, aes(x=YearQuarter, y=value,colour=Var.1)) +
geom_smooth(se=F, size=1.5)
x4.line <- x4.line + geom_text(aes(label = label),size = 3, hjust = 0.5, vjust =1.5)
### theme
x4.line <- x4.line + theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.background=element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank())
x4.line <- x4.line + ggtitle("Percentages:Main Reasons for Leaving Vodafone by Quarter") +
theme(plot.title = element_text(size=rel(1.2)))+
scale_y_continuous(labels=percent, limits=c(0,0.5)) +
scale_x_date(labels = date_format("%b-%y"),breaks = date_breaks("3 months"))+
labs(y="Percentage",x="Year Quarter")
x4.line
我建議閱讀'scale_x_date'你似乎已經知道的函數的文檔。請注意,它有一個破裂的說法。 – joran
我建議你喜歡@joran,你投入一點點來學習R和ggplot2,我們不是來做你的工作。我在前面的問題中爲你寫了這段代碼http://stackoverflow.com/questions/13692739/how-to-display-data-in-sep-12-format-in-a-line-chart-and-suppress- the-gridlines/13693472#13693472最小是瞭解它! – agstudy
我剛剛切換到R 2.15.2和最新版本的ggplot。我發現它與變化混淆。如果我和你一樣聰明,我不會問這個問題嗎?感謝您的迴應。但是,你圖沒有顯示我想要的順序...因此我問了這個問題。 當你第一次學習R時有一種想法,你有多少次遇到問題?呵呵..... –