How to separate one graph from different new graphs?

I have a database that includes laws in different years from 1985-2012. I would like to make different 17 graphs (and therefore make a function) for each year, which will include its β€œvalues ​​and years ago”, and also keep the same x and y axis diagram for each graph, as you can see in the following figure:

http://i.imgur.com/QttRuSl.png?1

As I made the chart above, between 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)) 

As I wrote earlier, I would like to have 17 different stories - in 1985, 1985 and 1986, in 1985 + 1986 + 1987, etc., and would have the same construction of the x and y axis (x axis from 1985: 2012 and y axis from 2 to 65).

How can I make a function to achieve it?

+4
source share
1 answer

if you call p , I would do the following:

 plyr::l_ply(v$year, function(.year) p %+% subset(v, year <= .year), .print=TRUE) 
+5
source

Source: https://habr.com/ru/post/1500021/


All Articles