rm(list = ls())
library(ggplot2)
library(treemapify)
library(treemap)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
data("GNI2014")
head(GNI2014)
##   iso3          country     continent population    GNI
## 3  BMU          Bermuda North America      67837 106140
## 4  NOR           Norway        Europe    4676305 103630
## 5  QAT            Qatar          Asia     833285  92200
## 6  CHE      Switzerland        Europe    7604467  88120
## 7  MAC Macao SAR, China          Asia     559846  76270
## 8  LUX       Luxembourg        Europe     491775  75990
GNI2014%>%filter(continent=="Asia")->Asia
head(Asia)
##   iso3              country continent population   GNI
## 1  QAT                Qatar      Asia     833285 92200
## 2  MAC     Macao SAR, China      Asia     559846 76270
## 3  SGP            Singapore      Asia    4657542 55150
## 4  KWT               Kuwait      Asia    2691158 49300
## 5  ARE United Arab Emirates      Asia    4798491 44600
## 6  JPN                Japan      Asia  127078679 42000
data_1 <- Asia
data_1$GNI <- 1:nrow(data_1)
data_1$population <- 1:nrow(data_1)
View(data_1)
head(data_1)
##   iso3              country continent population GNI
## 1  QAT                Qatar      Asia          1   1
## 2  MAC     Macao SAR, China      Asia          2   2
## 3  SGP            Singapore      Asia          3   3
## 4  KWT               Kuwait      Asia          4   4
## 5  ARE United Arab Emirates      Asia          5   5
## 6  JPN                Japan      Asia          6   6
ggplot(data_1, aes(area = GNI, fill = population)) +
  geom_treemap()

##
ggplot(data_1, aes(area = GNI, fill = population, label = country)) +
  geom_treemap() +
  geom_treemap_text(fontface = "italic", colour = "red", place = "centre",
                    grow = T)

###
ggplot(data_1, aes(area = GNI, fill = factor(population), label = country)) +
  geom_treemap() +
  geom_treemap_text(fontface = "italic", colour = "white", place = "centre",
                    grow = TRUE)

###
ggplot(data_1, aes(area = GNI, fill = population, label = country,
                 subgroup = continent)) +
  geom_treemap() +
  geom_treemap_subgroup_border() +
  geom_treemap_subgroup_text(place = "centre", grow = T, alpha = .5, colour =
                               "blue", fontface = "italic", min.size = 0) +
  geom_treemap_text(colour = "Red", place = "topleft", reflow = T)

###
ggplot(GNI2014, aes(area = GNI, fill = population, label = country,
                    subgroup = continent)) +
  geom_treemap() +
  geom_treemap_subgroup_border() +
  geom_treemap_subgroup_text(place = "centre", grow = T, alpha = .9, colour =
                               "White", fontface = "italic", min.size = 0) +
  geom_treemap_text(colour = "Red", place = "topleft", reflow = T)

###
ggplot(GNI2014, aes(area = GNI, fill = continent, label = country)) +
  geom_treemap() +
  geom_treemap_text(grow = T, reflow = T, colour = "black") +
  #facet_wrap( ~continent) +
  scale_fill_brewer(palette = "Set1") +
  theme(legend.position = "bottom") +
  labs(
    title = "The Gross National Income per capital 2014 ",
    caption = "The area of each country is proportional to its relative GNNI within the region",
    fill = "continent"
  )

###
ggplot(GNI2014, aes(area = GNI, fill = continent, label = country,
                    subgroup = continent)) +
  geom_treemap() +
  geom_treemap_subgroup_border() +
  geom_treemap_subgroup_text(place = "centre", grow = T, alpha = .9, colour =
                               "White", fontface = "italic", min.size = 0) +
  geom_treemap_text(colour = "Red", place = "topleft", reflow = T)+facet_wrap(~continent)+
  labs(title = "The Gross National Income per capital 2014 ",
       caption = "The area of each country is proportional to its relative GNI within the region",
       fill = "continent")

###
ggsave(filename = paste0(Sys.Date(),"-radar_2_protein.tif"), plot = last_plot(), 
       device = "tiff",
       scale = 1, width = 20, height =20, units = "cm",dpi = 300, limitsize = TRUE, compression = "lzw")