我想生成一个图表,使用ggplot2
每周从4月到6月标记y轴。
这是我的数据:
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
但是,我想在4月1日到6月1日之间每周给它贴上标签。我想我必须将离散标签传递给情节?
谢谢
-cherrytree
答案 0 :(得分:1)
要以这种方式更改yaxis,请使用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'))
那些确切的日期和breaks
的范围可能稍微偏离,但这是基本的想法。