Student Name: Senet Manandhar
Data received: Built in R studi0 - GNI2014
Treemapping is a method for displaying hierarchical data using nested figures, usually rectangles.(Wiki)
#devtools::install_github("wilkox/treemapify")
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")
View(GNI2014)
Installed Treemapify package
GNI2014%>%filter(continent=="Asia")->Asia
View(Asia)
ggplot(Asia, aes(area = GNI, fill = population)) +
geom_treemap()
In a treemap, each tile represents a single observation, with the area of the tile proportional to a variable.
ggplot(Asia, aes(area = GNI, fill = population, label = country)) +
geom_treemap() +
geom_treemap_text(fontface = "italic", colour = "white", place = "centre",
grow = TRUE)
ggplot(Asia, aes(area = GNI, fill = factor(population), label = country)) +
geom_treemap() +
geom_treemap_text(fontface = "italic", colour = "white", place = "centre",
grow = TRUE)
Only One continent(Asia)
ggplot(Asia, 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)
With all the continent
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"
)
##With Faceting
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 GNI",
fill = "continent"
)
#With using Subgroup
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")