【发布时间】:2014-12-24 03:36:37
【问题描述】:
我想生成一个图表,使用ggplot2 每周标记 y 轴,从 4 月到 6 月。
这是我的数据:
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
但是,我不想用一年中的某天标记 y 轴,而是想从 4 月 1 日到 6 月 1 日每周标记一次。我假设我必须将离散标签传递给情节?
谢谢
-樱桃树
【问题讨论】: