ggplot의 기본 날짜 간격이 확실하지 않습니다. 내 데이터에는 2011 년 9 월, 12 월, 3 월, 6 월, 9 월 등 5 가지 데이터 포인트가 있습니다.ggplot에서 기본 날짜 간격을 변경하는 방법은 무엇입니까?
ggplot은 내 데이터에서 다른 데이터 포인트를 표시합니다.이 데이터는 약간 성가신 것으로 나타났습니다. 내가 놓친 게 있니?
당신은 "표시하는 데 도움이 수 9 월 - 2011 년 12 월 - 2011 년 3 월 2012 이세 - 2012 년 9 월 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
에
breaks
인수에 필요한 휴식을 통과해야
나는'당신이 이미 알고있는 것처럼 기능을 scale_x_date'에 대한 설명서를 읽는 것이 좋습니다. 그것을 통지는 휴식 인수를 가지고 . – joran
나는 R과 ggplot2를 배우기 위해 당신이 조금 투자한다는 것을 @joran과 같이 제안한다, 우리는 당신의 일을하기 위해 여기에 있지 않다. 이전 질문에서이 코드를 작성했습니다. 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을 처음 배우던 때를 생각해보십시오. 몇 번이나 질문을하면서 몇 번이나 붙어 있습니까? hehe ..... –