Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(readxl)
- datfile <- "mpd_2013-01.xlsx"
- #excel_sheets(datfile)
- gdppc <- read_excel(datfile,sheet = 2,skip=2)
- names(gdppc)[1] <- 'year'
- # Drop data <1929 and >2009
- gdppc <- gdppc[148:227,]
- library(reshape2)
- compara <- melt(gdppc[,1:7],
- #compara <- melt(gdppc,
- id="year",
- variable.name = "Country",
- value.name = "GDPPC")
- library(ggplot2)
- myplot <- ggplot(data=compara, aes(x=year,y=GDPPC,color=Country))
- myplot +
- geom_line() +
- ggtitle("Economic history of major Caribbean countries") +
- labs(x="Year",y="GDP / capita \n[USD]")
- gdppcrel <- gdppc
- for (i in 2:8){
- gdppcrel[,i] <- 100*gdppcrel[,i]/gdppcrel[30,i]
- }
- compara2 <- melt(gdppcrel,
- id="year",
- variable.name = "Country",
- value.name = "GDPPCrel")
- library(grid) # needed for arrow function
- myplot2 <- ggplot(data=compara2, aes(x=year,y=GDPPCrel,color=Country))
- yplot2 +
- geom_line() +
- ggtitle("Economic history of major Caribbean countries") +
- labs(x="Year",y="GDP / capita \n[% of value in 1958]") +
- geom_segment(aes(x=1950,y=200,xend=1972,yend=170),
- color='#00BFC4',
- arrow=arrow(length = unit(10, "points"))) +
- annotate(geom="text",x=1950, y=200,
- label="People's National Party\nin Jamaica",
- color="#00BFC4") +
- geom_segment(aes(x=1940,y=130,xend=1958,yend=100),
- color='#F8766D',
- arrow=arrow(length = unit(10, "points"))) +
- annotate(geom="text",x=1940, y=130,
- label="Castro takes over\nCuba",
- color="#F8766D") +
- geom_segment(aes(x=1980,y=300,xend=1980,yend=250),
- color='#619CFF',
- arrow=arrow(length = unit(10, "points"))) +
- annotate(geom="text",x=1980, y=310,
- label="Latin American debt crisis",
- color="#619CFF")
- myplot2 +
- geom_line() +
- ggtitle("Economic history of major Caribbean countries") +
- labs(x="Year",y="GDP / capita \n[% of value in 1958]") +
- geom_segment(aes(x=1950,y=200,xend=1972,yend=170),
- color='#00BFC4',
- arrow=arrow(length = unit(10, "points"))) +
- annotate(geom="text",x=1950, y=200,
- label="People's National Party\nin Jamaica",
- color="#00BFC4") +
- geom_segment(aes(x=1940,y=130,xend=1958,yend=100),
- color='#F8766D',
- arrow=arrow(length = unit(10, "points"))) +
- annotate(geom="text",x=1940, y=130,
- label="Castro takes over\nCuba",
- color="#F8766D") +
- geom_segment(aes(x=1980,y=300,xend=1980,yend=250),
- color='#619CFF',
- arrow=arrow(length = unit(10, "points"))) +
- annotate(geom="text",x=1980, y=310,
- label="Latin American debt crisis",
- color="#619CFF") +
- geom_segment(aes(x=1940,y=40,xend=2010,yend=300),
- color='black',
- arrow=arrow(length = unit(10, "points"))) +
- geom_segment(aes(x=1960,y=100,xend=2010,yend=150),
- color='#F8766D',
- arrow=arrow(length = unit(10, "points"))) +
- geom_segment(aes(x=1972,y=160,xend=2010,yend=160),
- color='#00BFC4',
- arrow=arrow(length = unit(10, "points")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement