2014-10-28 59 views
0

我想制作一个图表,标签y轴每周从四月到六月使用ggplot2标签y轴以一周为增量ggplot2

这里是我的数据:

df <- structure(list(year = structure(1:11, .Label = c("2000", "2001", 
"2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", 
"2010"), class = "factor"), greenups_mean = c(107, 106, 124, 
107, 119, 112, 103, 113, 133, 127, 109), greenups.dtime = structure(c(11063, 
11428, 11811, 12159, 12536, 12895, 13251, 13626, 14011, 14371, 
14718), class = "Date"), gmd = c("04-16", "04-16", "05-04", "04-17", 
"04-28", "04-22", "04-13", "04-23", "05-12", "05-07", "04-19" 
)), row.names = c(NA, -11L), class = "data.frame", .Names = c("year", 
"greenups_mean", "greenups.dtime", "gmd")) 

我可以产生一个像样的线图。我使用y轴上的一年中的一天df$greenups_mean

library (ggplot2) 
p <- ggplot (df,aes(x=year,y=greenups_mean)) + geom_line(aes(group=1)) 
p <- p + ylab('Green-up') + xlab('Year') 
p 

enter image description here

,但不用标记y轴与去年的一天,我想喜欢从4月1日每周进行标记,6月1日。我假设我必须将不连续的标签传递给情节?

感谢

-cherrytree

回答

1

要改变y轴以这种方式,使用scale_y_continuous

p <- ggplot (df,aes(x=year,y=greenups_mean)) + geom_line(aes(group=1)) 
p <- p + ylab('Green-up') + xlab('Year') 
p + scale_y_continuous(breaks=seq(91,152,length.out=9),limit=c(90,152),labels=c('Apr 1','Apr 8','Apr 15','Apr 22','Apr 29','May 6', 'May 13', 'May 20','May 27')) 

enter image description here

那些确切的日期和breaks范围可能有点过,但这是基本的想法。

+0

其实,我想要在Y轴上每周刻度标记,而不是X轴,只需要两个月。因此,4月和5月的8周只有8个刻度线。 – cherrytree 2014-10-28 16:43:27

+0

'绿色'是指一年中的哪一天? – keegan 2014-10-28 16:48:23

+0

是的,绿色指的是一年中的某一天。 – cherrytree 2014-10-28 16:50:29