There was a break in the recording of weight for trade flows reported by France between 2006 and 2010. Investigate this issue.
library(knitr) opts_knit$set(root.dir="../../..") # file paths are relative to the root of the project directory library(tradeflows) library(dplyr) library(reshape2) library(ggplot2) getwd()
# load raw data and rename it load("data/sawnwoodexample.rda") # if the format has change, sawnwood <- sawnwoodexample sawnwoodexample %>% select(reporter, productcode) %>% unique()
Load data for france Alexandra said that there is missing weight values between 2006 and 2010, but I only see missing values for 2012.
Load data from comtrade for an example file of missing data. Paste this data to Excel.
swdoakfr <- loadcomtrade_bycode(440791, 251, "recent") unique(swdoakfr$yr) # add 5 years before swdoakfr2 <- loadcomtrade_bycode(440791, 251,seq(2004,2008)) swdoakfr <- rbind(swdoakfr, swdoakfr2) swdoakfr <- swdoakfr %>% arrange(yr, rgCode, ptCode) unique(swdoakfr$yr[is.na(swdoakfr$NetWeight)]) unique(swdoakfr[c("yr","pfCode")]) xlsx::write.xlsx(swdoakfr,file="data-raw/swdoakfr.xlsx") # write.xlsx2 is slightly faster on first use. Immensely faster on second use. system.time(xlsx::write.xlsx(swdoakfr,file="data-raw/swdoakfr.xlsx")) # user system elapsed # 14.397 0.056 14.430 system.time(xlsx::write.xlsx2(swdoakfr,file="data-raw/swdoakfr.xlsx")) # user system elapsed # 0.520 0.064 0.601
# Data for French sawnwood oak swdoakfr <- sawnwood %>% filter(productcode == 440791 & reporter=="France") %>% select(classification, year, quantity, weight, tradevalue) %>% melt(id=c("classification", "year")) %>% mutate(value = !is.na(value)) %>% unique # Add product name and title to the plot ggplot(data=swdoakfr,aes(x=year, y=variable, xend=year+1, yend=variable, color=value, linetype=value)) + geom_segment(size=3) + facet_grid(classification~.)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.