[英]How to separate one graph to different new graphs?
我有一個數據庫,其中包括1985 - 2012年間不同年份的法律。 我想為每年制作不同的17個圖(因此,制作一個函數),包括它的'值和前幾年,並為每個圖保持相同的x和y軸設計,如你所見在下圖中:
這就是我在1985年至2012年間制作上圖的方式:
> v <- ddply(leg.by.melt, .(year), summarise, count = sum(value))
> v
year count
1 1985 2
2 1987 5
3 1988 9
4 1989 12
5 1990 14
6 1991 11
7 1992 16
8 1993 23
9 1994 25
10 1995 10
11 1996 11
12 1997 24
13 1998 35
14 1999 32
15 2000 24
16 2001 22
17 2002 65
18 2003 42
19 2004 56
20 2005 42
21 2006 47
22 2007 36
23 2008 16
24 2009 54
25 2011 28
> ggplot(v, aes(x = year, y = count))
+ theme_bw()
+ geom_contour(colour = "black", lty = 3, lend = 2, lwd = 1, stat = "identity")
+ scale_x_continuous(breaks = round(seq(min(v$year), max(v$year), by = 1),1))
+ scale_y_continuous(breaks = round(seq(min(v$count), max(v$count), by = 3),1))
+ theme(axis.text.x = element_text(angle = 0, vjust = 0.2))
正如我之前寫的那樣,我希望有一個不同的17個圖 - 1985年,1985年+ 1986年,1985年+ 1986年+ 1987年等等,並且依舊設計x和y軸(x軸來自1985:2012年,y軸從2到65)。
我怎樣才能實現它的功能呢?
如果你的情節被稱為p
,我會做以下事情,
plyr::l_ply(v$year, function(.year) p %+% subset(v, year <= .year), .print=TRUE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.