library(ggplot2)
library(dplyr)
library(reshape2)
Explore some of the ggplot2 functions for use in the project
ggplot(iris,
aes(x=Petal.Length, y=Petal.Width, color=Species)) +
geom_point()
Use aesthetic to make points more transparent on a coutry * contry grid display trade volume as alpha level.
df <- data.frame(x = rnorm(5000), y = rnorm(5000))
ggplot(df, aes(x,y)) + geom_point(alpha = 1/10)
b <- ggplot(economics, aes(x = date, y = unemploy))
j <- b + geom_line()
# j # uncomment to display basic plot
yrng <- range(economics$unemploy)
j <- j + geom_rect(aes(NULL, NULL, xmin = start, xmax = end, fill = party),
ymin = yrng[1], ymax = yrng[2], data = presidential)
# j
library(scales) # to access the alpha function
j + scale_fill_manual(values = alpha(c("blue", "red"), .3))
For some countries, the completeness table contained only true values. WHIch were rendered as red lines, for other countries true values were rendered as blue lines. Changed this behaviour by using manual color palettes for colours scale_colour_manual() and line palette for lines scale_linetype_manual().
# plot completeness
rawdata <- tradeflows::sawnwoodexample
r <- "France"
productcodeinreport <- 4407
completeness <- rawdata %>%
filter(productcode == 4407) %>%
select(reporter, classification, year, quantity, weight, tradevalue) %>%
melt(id=c("reporter", "classification", "year")) %>%
mutate(value = !is.na(value)) %>%
unique %>%
arrange(classification, reporter, year)
p <- ggplot(data=filter(completeness, reporter == r),
aes(x=year, y=variable,
xend=year+1, yend=variable,
color=value, linetype=value)) +
scale_colour_manual(values = c("TRUE" = "blue", "FALSE" = "red")) +
scale_linetype_manual(values = c("TRUE" = 2, "FALSE" = 1)) +
#"solid", "dashed"
geom_segment(size=3) +
facet_grid(classification~.) +
ggtitle(paste("Data completeness of", productcodeinreport,
"in", r))
plot(p)