how to join two data frames in R(inner,outer, left, right) and plot the resultant multiple time series witth legend? -


i used of following codes merge 2 of data frames:

join(j5, c4, inner") merge(j5, c4, left_on='year', how='inner') 

the resultant data frame being:

   year tradevaluejapan tradevaluechina 1  1992         1215216          265860 2  1993          654958          300987 3  1994         1058199          693368 4  1995         4827964         1608935 5  1996         2882890         1457594 6  1997         5859965          880888 7  1998         3499868          859137 8  1999         3530975         1069889 9  2000          439580         2026727 10 2001         9808706         2675847 11 2002         9358647         4568524 12 2003         1348892         4608139 13 2004          945569         6619693 14 2005          738876        14812109 15 2006         1453525        17870811 16 2007         9335089        19904723 17 2008         5391225        26881686 18 2009           55391        18815007 19 2010         1246401        20065842 20 2011           25783        19004412 21 2012           88171        17278793 22 2013          329110        19116949 23 2014         1066022        32076571 

separately, learnt how plot multiple time series using codes following link: plot multiples (time) series in r legend

but how can plot resultant merged data frame multiple time series?

after merge, create 'xts' object ordered date (which created 'year' column), , use plot.xts

 library(xts)  library(xtsextra)   df1 <- merge(j5, c4, left_on='year', how='inner')  xt1 <- xts(df1[-1], order.by=as.date(paste0(df1$year,'-01-01')))  plot.xts(xt1) 

data

df1 <- structure(list(year = 1992:2014, tradevaluejapan = c(1215216l,  654958l, 1058199l, 4827964l, 2882890l, 5859965l, 3499868l, 3530975l,  439580l, 9808706l, 9358647l, 1348892l, 945569l, 738876l, 1453525l,  9335089l, 5391225l, 55391l, 1246401l, 25783l, 88171l, 329110l,  1066022l), tradevaluechina = c(265860l, 300987l, 693368l, 1608935l,  1457594l, 880888l, 859137l, 1069889l, 2026727l, 2675847l, 4568524l,  4608139l, 6619693l, 14812109l, 17870811l, 19904723l, 26881686l,  18815007l, 20065842l, 19004412l, 17278793l, 19116949l, 32076571l )), .names = c("year", "tradevaluejapan", "tradevaluechina"),  class = "data.frame", row.names = c("1",  "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",  "14", "15", "16", "17", "18", "19", "20", "21", "22", "23")) 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -