library(treemap)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.0 v dplyr 1.0.4
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(RColorBrewer)
data <- read.csv("http://datasets.flowingdata.com/post-data.txt")
head(data)
## id views comments category
## 1 5019 148896 28 Artistic Visualization
## 2 1416 81374 26 Visualization
## 3 1416 81374 26 Featured
## 4 3485 80819 37 Featured
## 5 3485 80819 37 Mapping
## 6 3485 80819 37 Data Sources
treemap(data, index="category", vSize="views",
vColor="comments", type="value",
palette="RdYlBu")
treemap(data, index="category", vSize="views",
vColor="comments", type="manual",
palette="RdYlBu")
library(tidyverse)
nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv")
head(nba)
## Name G MIN PTS FGM FGA FGP FTM FTA FTP X3PM X3PA X3PP ORB
## 1 Dwyane Wade 79 38.6 30.2 10.8 22.0 0.491 7.5 9.8 0.765 1.1 3.5 0.317 1.1
## 2 LeBron James 81 37.7 28.4 9.7 19.9 0.489 7.3 9.4 0.780 1.6 4.7 0.344 1.3
## 3 Kobe Bryant 82 36.2 26.8 9.8 20.9 0.467 5.9 6.9 0.856 1.4 4.1 0.351 1.1
## 4 Dirk Nowitzki 81 37.7 25.9 9.6 20.0 0.479 6.0 6.7 0.890 0.8 2.1 0.359 1.1
## 5 Danny Granger 67 36.2 25.8 8.5 19.1 0.447 6.0 6.9 0.878 2.7 6.7 0.404 0.7
## 6 Kevin Durant 74 39.0 25.3 8.9 18.8 0.476 6.1 7.1 0.863 1.3 3.1 0.422 1.0
## DRB TRB AST STL BLK TO PF
## 1 3.9 5.0 7.5 2.2 1.3 3.4 2.3
## 2 6.3 7.6 7.2 1.7 1.1 3.0 1.7
## 3 4.1 5.2 4.9 1.5 0.5 2.6 2.3
## 4 7.3 8.4 2.4 0.8 0.8 1.9 2.2
## 5 4.4 5.1 2.7 1.0 1.4 2.5 3.1
## 6 5.5 6.5 2.8 1.3 0.7 3.0 1.8
nba <- nba[order(nba$PTS),]
row.names(nba) <- nba$Name
nba <- nba[,2:19]
nba_matrix <- data.matrix(nba)
head(nba_matrix)
## G MIN PTS FGM FGA FGP FTM FTA FTP X3PM X3PA X3PP ORB
## Nate Robinson 74 29.9 17.2 6.1 13.9 0.437 3.4 4.0 0.841 1.7 5.2 0.325 1.3
## Allen Iverson 57 36.7 17.5 6.1 14.6 0.417 4.8 6.1 0.781 0.5 1.7 0.283 0.5
## Rashard Lewis 79 36.2 17.7 6.1 13.8 0.439 2.8 3.4 0.836 2.8 7.0 0.397 1.2
## Chauncey Billups 79 35.3 17.7 5.2 12.4 0.418 5.3 5.8 0.913 2.1 5.0 0.408 0.4
## Maurice Williams 81 35.0 17.8 6.5 13.9 0.467 2.6 2.8 0.912 2.3 5.2 0.436 0.6
## Shaquille O'neal 75 30.1 17.8 6.8 11.2 0.609 4.1 6.9 0.595 0.0 0.0 0.000 2.5
## DRB TRB AST STL BLK
## Nate Robinson 2.6 3.9 4.1 1.3 0.1
## Allen Iverson 2.5 3.0 5.0 1.5 0.1
## Rashard Lewis 4.6 5.7 2.6 1.0 0.6
## Chauncey Billups 2.6 3.0 6.4 1.2 0.2
## Maurice Williams 2.9 3.4 4.1 0.9 0.1
## Shaquille O'neal 5.9 8.4 1.7 0.7 1.4
## Heatmap with cm (cool) colors
nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA,
col = cm.colors(256), scale="column", margins=c(5,10),
main = "NBA cool color heatmap", ylab = "Player", xlab = "Stat")
## Heatmap with heat colors
nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA,
col = heat.colors(256, rev=TRUE), scale="column", margins=c(5,10),
main = "NBA warm color heatmap", ylab = "Player", xlab = "Stat")
library(viridis)
## Loading required package: viridisLite
## Loading required package: viridisLite
## heatmap using viridis colors
nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA,
col = viridis(25, direction = -1),
scale="column",
main = "NBA Viridis color heatmap")
pacman:: p_load(nycflights13) # load required libraries
pacman:: p_load(RColorBrewer)
head(flights)
## # A tibble: 6 x 19
## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
## <int> <int> <int> <int> <int> <dbl> <int> <int>
## 1 2013 1 1 517 515 2 830 819
## 2 2013 1 1 533 529 4 850 830
## 3 2013 1 1 542 540 2 923 850
## 4 2013 1 1 544 545 -1 1004 1022
## 5 2013 1 1 554 600 -6 812 837
## 6 2013 1 1 554 558 -4 740 728
## # ... with 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
## # hour <dbl>, minute <dbl>, time_hour <dttm>
flights_nona <- na.omit (flights) # remove observations with NA values
delays <- flights_nona %>% # create a delays dataframe by:
group_by (dest) %>% # grouping by point of destination
summarize (count = n(), # creating variables: number of flights to each destination,
dist = mean (distance), # the mean distance flown to each destination,
delay = mean (arr_delay), # the mean delay of arrival to each destination,
delaycost = mean(count*delay/dist)) # delay cost index defined as:
# [(number of flights)*delay/distance] for a destination
delays <- arrange(delays, desc(delaycost)) # sort the rows by delay cost
head(delays) # look at the data
## # A tibble: 6 x 5
## dest count dist delay delaycost
## <chr> <int> <dbl> <dbl> <dbl>
## 1 DCA 9111 211. 9.07 391.
## 2 IAD 5383 225. 13.9 332.
## 3 ATL 16837 757. 11.3 251.
## 4 BOS 15022 191. 2.91 230.
## 5 CLT 13674 538. 7.36 187.
## 6 RDU 7770 427. 10.1 183.
This gives Reagan National (DCA) with the highest delay cost. Now get the top 100 and create the heatmap.
top100 <- delays %>% # select the 100 largest delay costs
head(100) %>%
arrange(delaycost) # sort ascending so the heatmap displays descending costs
row.names(top100) <- top100$dest # rename the rows according to destination airport codes
## Warning: Setting row names on a tibble is deprecated.
delays_mat <- data.matrix(top100) # convert delays dataframe to a matrix (required by heatmap)
delays_mat_ <- delays_mat[,2:5] # remove the redundant column of destination airport codes
# Call heatmap using a ColorBrewer color set, margins=c(7,10) for aspect ratio, titles of graph, x and y labels,
# font size of x and y labels, and set up a RowSideColors bar
varcols = setNames(colorRampPalette(brewer.pal(nrow(delays_mat_), "YlGnBu"))(nrow(delays_mat_)),
rownames(delays_mat_)) # parameter for RowSideColors
## Warning in brewer.pal(nrow(delays_mat_), "YlGnBu"): n too large, allowed maximum for palette YlGnBu is 9
## Returning the palette you asked for with that many colors
## Warning in brewer.pal(nrow(delays_mat_), "YlGnBu"): n too large, allowed maximum for palette YlGnBu is 9
## Returning the palette you asked for with that many colors
heatmap(delays_mat_,
Rowv = NA, Colv = NA,
col= colorRampPalette(brewer.pal(nrow(delays_mat_), "YlGnBu"))(nrow(delays_mat_)),
s=0.6, v=1, scale="column",
margins=c(7,10),
main = "Cost of Late Arrivals",
xlab = "Flight Characteristics",
ylab="Arrival Airport", labCol = c("Flights","Distance","Delay","Cost Index"),
cexCol=1, cexRow =1, RowSideColors = varcols)
## layout: widths = 0.05 0.2 4 , heights = 0.25 4 ; lmat=
## [,1] [,2] [,3]
## [1,] 0 0 4
## [2,] 3 1 2
## Warning in brewer.pal(nrow(delays_mat_), "YlGnBu"): n too large, allowed maximum for palette YlGnBu is 9
## Returning the palette you asked for with that many colors
devtools::install_github("hrbrmstr/streamgraph")
## Skipping install of 'streamgraph' from a github remote, the SHA1 (76f7173e) has not changed since last install.
## Use `force = TRUE` to force installation
devtools::session_info()
## - Session info ---------------------------------------------------------------
## setting value
## version R version 4.0.3 (2020-10-10)
## os Windows 10 x64
## system x86_64, mingw32
## ui RTerm
## language (EN)
## collate English_United States.1252
## ctype English_United States.1252
## tz America/New_York
## date 2021-03-01
##
## - Packages -------------------------------------------------------------------
## package * version date lib source
## assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.3)
## backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.3)
## broom 0.7.5 2021-02-19 [1] CRAN (R 4.0.3)
## bslib 0.2.4 2021-01-25 [1] CRAN (R 4.0.3)
## cachem 1.0.4 2021-02-13 [1] CRAN (R 4.0.3)
## callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.3)
## cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.0.3)
## cli 2.3.1 2021-02-23 [1] CRAN (R 4.0.3)
## colorspace 2.0-0 2020-11-11 [1] CRAN (R 4.0.3)
## crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.3)
## curl 4.3 2019-12-02 [1] CRAN (R 4.0.3)
## data.table 1.14.0 2021-02-21 [1] CRAN (R 4.0.3)
## DBI 1.1.1 2021-01-15 [1] CRAN (R 4.0.3)
## dbplyr 2.1.0 2021-02-03 [1] CRAN (R 4.0.3)
## desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.3)
## devtools 2.3.2 2020-09-18 [1] CRAN (R 4.0.3)
## digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3)
## dplyr * 1.0.4 2021-02-02 [1] CRAN (R 4.0.3)
## ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.3)
## evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.3)
## fansi 0.4.2 2021-01-15 [1] CRAN (R 4.0.3)
## fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.0.3)
## forcats * 0.5.1 2021-01-27 [1] CRAN (R 4.0.3)
## fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.3)
## generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.3)
## ggplot2 * 3.3.3 2020-12-30 [1] CRAN (R 4.0.3)
## glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.3)
## gridBase 0.4-7 2014-02-24 [1] CRAN (R 4.0.3)
## gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.3)
## gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.3)
## haven 2.3.1 2020-06-01 [1] CRAN (R 4.0.3)
## highr 0.8 2019-03-20 [1] CRAN (R 4.0.3)
## hms 1.0.0 2021-01-13 [1] CRAN (R 4.0.3)
## htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.0.3)
## httpuv 1.5.5 2021-01-13 [1] CRAN (R 4.0.3)
## httr 1.4.2 2020-07-20 [1] CRAN (R 4.0.3)
## igraph 1.2.6 2020-10-06 [1] CRAN (R 4.0.3)
## jquerylib 0.1.3 2020-12-17 [1] CRAN (R 4.0.3)
## jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.0.3)
## knitr 1.31 2021-01-27 [1] CRAN (R 4.0.3)
## later 1.1.0.1 2020-06-05 [1] CRAN (R 4.0.3)
## lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.4)
## lubridate 1.7.9.2 2020-11-13 [1] CRAN (R 4.0.3)
## magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.3)
## memoise 2.0.0 2021-01-26 [1] CRAN (R 4.0.3)
## mime 0.10 2021-02-13 [1] CRAN (R 4.0.4)
## modelr 0.1.8 2020-05-19 [1] CRAN (R 4.0.3)
## munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.3)
## nycflights13 * 1.0.1 2019-09-16 [1] CRAN (R 4.0.3)
## pacman 0.5.1 2019-03-11 [1] CRAN (R 4.0.3)
## pillar 1.5.0 2021-02-22 [1] CRAN (R 4.0.3)
## pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.0.3)
## pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.3)
## pkgload 1.2.0 2021-02-23 [1] CRAN (R 4.0.3)
## prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.3)
## processx 3.4.5 2020-11-30 [1] CRAN (R 4.0.3)
## promises 1.2.0.1 2021-02-11 [1] CRAN (R 4.0.3)
## ps 1.5.0 2020-12-05 [1] CRAN (R 4.0.3)
## purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.0.3)
## R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.3)
## RColorBrewer * 1.1-2 2014-12-07 [1] CRAN (R 4.0.3)
## Rcpp 1.0.6 2021-01-15 [1] CRAN (R 4.0.3)
## readr * 1.4.0 2020-10-05 [1] CRAN (R 4.0.3)
## readxl 1.3.1 2019-03-13 [1] CRAN (R 4.0.3)
## remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.3)
## reprex 1.0.0 2021-01-27 [1] CRAN (R 4.0.3)
## rlang 0.4.10 2020-12-30 [1] CRAN (R 4.0.3)
## rmarkdown 2.7 2021-02-19 [1] CRAN (R 4.0.3)
## rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.3)
## rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.0.3)
## rvest 0.3.6 2020-07-25 [1] CRAN (R 4.0.3)
## sass 0.3.1 2021-01-24 [1] CRAN (R 4.0.3)
## scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.3)
## sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.3)
## shiny 1.6.0 2021-01-25 [1] CRAN (R 4.0.3)
## stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.3)
## stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.0.3)
## testthat 3.0.2 2021-02-14 [1] CRAN (R 4.0.4)
## tibble * 3.1.0 2021-02-25 [1] CRAN (R 4.0.3)
## tidyr * 1.1.2 2020-08-27 [1] CRAN (R 4.0.3)
## tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.3)
## tidyverse * 1.3.0 2019-11-21 [1] CRAN (R 4.0.3)
## treemap * 2.4-2 2017-01-04 [1] CRAN (R 4.0.3)
## usethis 2.0.1 2021-02-10 [1] CRAN (R 4.0.3)
## utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.3)
## vctrs 0.3.6 2020-12-17 [1] CRAN (R 4.0.3)
## viridis * 0.5.1 2018-03-29 [1] CRAN (R 4.0.3)
## viridisLite * 0.3.0 2018-02-01 [1] CRAN (R 4.0.3)
## withr 2.4.1 2021-01-26 [1] CRAN (R 4.0.3)
## xfun 0.21 2021-02-10 [1] CRAN (R 4.0.3)
## xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.3)
## xtable 1.8-4 2019-04-21 [1] CRAN (R 4.0.3)
## yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.3)
##
## [1] C:/Users/Owner/Documents/R/win-library/4.0
## [2] C:/Program Files/R/R-4.0.3/library
library(dplyr)
library(streamgraph)
library(babynames)
# Create data:
year=rep(seq(1991,2017) , each=10)
name=rep(letters[11:20] , 27)
value=sample( seq(0,1,0.0001) , length(year))
data=data.frame(year, name, value)
# Basic stream graph: just give the 3 arguments
streamgraph(data, key="name", value="value", date="year")
## Warning in widget_html(name = class(x)[1], package = attr(x, "package"), :
## streamgraph_html returned an object of class `list` instead of a `shiny.tag`.
ncol(babynames)
## [1] 5
head(babynames)
## # A tibble: 6 x 5
## year sex name n prop
## <dbl> <chr> <chr> <int> <dbl>
## 1 1880 F Mary 7065 0.0724
## 2 1880 F Anna 2604 0.0267
## 3 1880 F Emma 2003 0.0205
## 4 1880 F Elizabeth 1939 0.0199
## 5 1880 F Minnie 1746 0.0179
## 6 1880 F Margaret 1578 0.0162
str(babynames)
## tibble [1,924,665 x 5] (S3: tbl_df/tbl/data.frame)
## $ year: num [1:1924665] 1880 1880 1880 1880 1880 1880 1880 1880 1880 1880 ...
## $ sex : chr [1:1924665] "F" "F" "F" "F" ...
## $ name: chr [1:1924665] "Mary" "Anna" "Emma" "Elizabeth" ...
## $ n : int [1:1924665] 7065 2604 2003 1939 1746 1578 1472 1414 1320 1288 ...
## $ prop: num [1:1924665] 0.0724 0.0267 0.0205 0.0199 0.0179 ...
Mouse over the colors and years to look at the pattern of various names
babynames %>%
filter(grepl("^Ola", name)) %>%
group_by(year, name) %>%
tally(wt=n) %>%
streamgraph("name", "n", "year") %>%
sg_legend(TRUE, "Name: ")
## Warning in widget_html(name = class(x)[1], package = attr(x, "package"), :
## streamgraph_html returned an object of class `list` instead of a `shiny.tag`.
# Streamgraphing Commercial Real Estate Transaction Volume by Asset Class Since 2001
dat <- read.csv("http://asbcllc.com/blog/2015/february/cre_stream_graph_test/data/cre_transaction-data.csv")
dat %>%
streamgraph("asset_class", "volume_billions", "year", interpolate="linear") %>%
sg_axis_x(1, "year", "%Y") %>%
# sg_fill_manual(c(2:10))
sg_fill_brewer("Paired")
## Warning in widget_html(name = class(x)[1], package = attr(x, "package"), :
## streamgraph_html returned an object of class `list` instead of a `shiny.tag`.
Load the alluvial package
#install.packages("alluvial")
library(alluvial)
If you want to save the prebuilt dataset to your folder, use the write_csv function
alluvial::Refugees
## country year refugees
## 1 Afghanistan 2003 2136043
## 2 Burundi 2003 531637
## 3 Congo DRC 2003 453465
## 4 Iraq 2003 368580
## 5 Myanmar 2003 151384
## 6 Palestine 2003 350568
## 7 Somalia 2003 402336
## 8 Sudan 2003 606242
## 9 Syria 2003 20819
## 10 Vietnam 2003 363179
## 11 Afghanistan 2004 2084109
## 12 Burundi 2004 485454
## 13 Congo DRC 2004 461042
## 14 Iraq 2004 311905
## 15 Myanmar 2004 161013
## 16 Palestine 2004 350617
## 17 Somalia 2004 389304
## 18 Sudan 2004 730647
## 19 Syria 2004 21440
## 20 Vietnam 2004 349809
## 21 Afghanistan 2005 2166149
## 22 Burundi 2005 438706
## 23 Congo DRC 2005 430929
## 24 Iraq 2005 262299
## 25 Myanmar 2005 164864
## 26 Palestine 2005 349673
## 27 Somalia 2005 395553
## 28 Sudan 2005 693632
## 29 Syria 2005 16401
## 30 Vietnam 2005 358268
## 31 Afghanistan 2006 2107519
## 32 Burundi 2006 396541
## 33 Congo DRC 2006 401914
## 34 Iraq 2006 1450905
## 35 Myanmar 2006 202826
## 36 Palestine 2006 334142
## 37 Somalia 2006 464252
## 38 Sudan 2006 686311
## 39 Syria 2006 12338
## 40 Vietnam 2006 374279
## 41 Afghanistan 2007 1909911
## 42 Burundi 2007 375715
## 43 Congo DRC 2007 370386
## 44 Iraq 2007 2279245
## 45 Myanmar 2007 191256
## 46 Palestine 2007 335219
## 47 Somalia 2007 455356
## 48 Sudan 2007 523032
## 49 Syria 2007 13671
## 50 Vietnam 2007 327776
## 51 Afghanistan 2008 1817913
## 52 Burundi 2008 281592
## 53 Congo DRC 2008 367995
## 54 Iraq 2008 1873519
## 55 Myanmar 2008 184347
## 56 Palestine 2008 333990
## 57 Somalia 2008 559153
## 58 Sudan 2008 397013
## 59 Syria 2008 15186
## 60 Vietnam 2008 328183
## 61 Afghanistan 2009 1905804
## 62 Burundi 2009 94239
## 63 Congo DRC 2009 455852
## 64 Iraq 2009 1785212
## 65 Myanmar 2009 206650
## 66 Palestine 2009 95177
## 67 Somalia 2009 678308
## 68 Sudan 2009 348500
## 69 Syria 2009 17884
## 70 Vietnam 2009 339289
## 71 Afghanistan 2010 3054709
## 72 Burundi 2010 84064
## 73 Congo DRC 2010 476693
## 74 Iraq 2010 1683575
## 75 Myanmar 2010 215644
## 76 Palestine 2010 93299
## 77 Somalia 2010 770148
## 78 Sudan 2010 379067
## 79 Syria 2010 18428
## 80 Vietnam 2010 338698
## 81 Afghanistan 2011 2664436
## 82 Burundi 2011 101288
## 83 Congo DRC 2011 491481
## 84 Iraq 2011 1428308
## 85 Myanmar 2011 214594
## 86 Palestine 2011 94121
## 87 Somalia 2011 1075148
## 88 Sudan 2011 491013
## 89 Syria 2011 19900
## 90 Vietnam 2011 337829
## 91 Afghanistan 2012 2586034
## 92 Burundi 2012 73362
## 93 Congo DRC 2012 509082
## 94 Iraq 2012 746181
## 95 Myanmar 2012 215338
## 96 Palestine 2012 94820
## 97 Somalia 2012 1136713
## 98 Sudan 2012 558195
## 99 Syria 2012 728603
## 100 Vietnam 2012 336939
## 101 Afghanistan 2013 2556507
## 102 Burundi 2013 72652
## 103 Congo DRC 2013 499320
## 104 Iraq 2013 401384
## 105 Myanmar 2013 222053
## 106 Palestine 2013 96044
## 107 Somalia 2013 1121772
## 108 Sudan 2013 636400
## 109 Syria 2013 2457255
## 110 Vietnam 2013 314105
Refugees <- Refugees
write_csv(Refugees, "refugees.csv")
Use the alluvial_ts function to create the alluvial
Alluvials need the variables: category, time-variable, value
set.seed(39) # for nice colours
cols <- hsv(h = sample(1:10/10), s = sample(3:12)/15, v = sample(3:12)/15) # creates the vector of 10 colors
alluvial_ts(Refugees, wave = .3, ygap = 5, col = cols, plotdir = 'centred', alpha=.9,
grid = TRUE, grid.lwd = 5, xmargin = 0.2, lab.cex = .7, xlab = '',
ylab = '', border = NA, axis.cex = .8, leg.cex = .7,
leg.col='white',
title = "UNHCR-recognised refugees\nTop 10 countries (2003-2013)\n")