Assignment 04

Original

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.4.1 
✔ readr   2.1.2      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(readxl)
path <- "assignment02_happyPlanetData.xlsx"
hpi <- read_xlsx(path, sheet = "1. All countries", range="A9:L161")
New names:
• `` -> `...4`
summary(hpi)
    HPI rank        Country              ISO                ...4          
 Min.   :  1.00   Length:152         Length:152         Length:152        
 1st Qu.: 38.75   Class :character   Class :character   Class :character  
 Median : 76.50   Mode  :character   Mode  :character   Mode  :character  
 Mean   : 76.50                                                           
 3rd Qu.:114.25                                                           
 Max.   :152.00                                                           
   Continent     Population (thousands) Life Expectancy (years)
 Min.   :1.000   Min.   :    299.9      Min.   :53.30          
 1st Qu.:3.000   1st Qu.:   4970.4      1st Qu.:67.25          
 Median :5.000   Median :  11521.8      Median :74.65          
 Mean   :4.717   Mean   :  49738.8      Mean   :73.06          
 3rd Qu.:7.000   3rd Qu.:  37530.2      3rd Qu.:78.62          
 Max.   :8.000   Max.   :1433783.7      Max.   :84.90          
 Ladder of life (Wellbeing) (0-10) Ecological Footprint (g ha)      HPI       
 Min.   :2.375                     Min.   : 0.5157             Min.   :24.33  
 1st Qu.:4.819                     1st Qu.: 1.5019             1st Qu.:39.32  
 Median :5.526                     Median : 2.5710             Median :44.70  
 Mean   :5.532                     Mean   : 3.3252             Mean   :44.55  
 3rd Qu.:6.282                     3rd Qu.: 4.4461             3rd Qu.:50.87  
 Max.   :7.780                     Max.   :15.0376             Max.   :62.06  
 Biocapacity for year \r\n(g ha) GDP per capita ($)
 Min.   :1.56                    Length:152        
 1st Qu.:1.56                    Class :character  
 Median :1.56                    Mode  :character  
 Mean   :1.56                                      
 3rd Qu.:1.56                                      
 Max.   :1.56                                      
hpi <- subset(hpi, select=-...4) # drop ...4 column
names(hpi) = c('rank', 'country', 'iso', 'continent', 'population', 'life_exp', 'wellbeing', 'footprint', 'hpi', 'biocapacity', 'gdp') # rename columns
class(hpi$gdp) = "double" # set gdp from character to double
Warning in class(hpi$gdp) = "double": NAs introduced by coercion
ggplot(hpi) + 
  geom_dotplot(aes(x=hpi)) + 
  facet_wrap(vars(continent))
Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.

test <- read_xlsx("test_data.xlsx")
summary(test)
     height          weight     
 Min.   : 10.0   Min.   : 2.00  
 1st Qu.: 40.0   1st Qu.:28.00  
 Median : 50.0   Median :47.00  
 Mean   : 49.7   Mean   :52.39  
 3rd Qu.: 70.0   3rd Qu.:84.00  
 Max.   :100.0   Max.   :94.00  
ggplot(test) + 
  geom_histogram(aes(x=height), 
                 color='steelblue4', 
                 fill='steelblue3', 
                 breaks=unique(test$weight))

Edited

# import fonts
library(extrafont)
Registering fonts with R
#font_import()
loadfonts()

ggplot(hpi) + 
  geom_dotplot(aes(x=hpi),
               color = "black",
               fill = "salmon") + 
  facet_wrap(vars(continent)) + 
  theme(text = element_text(family="Times")) +
  labs(title = "Human Planet Index",
       subtitle = "Year of 2022",
       caption = "HPI by continent",
       tag = "Figure 1",
       x = "HPI",
       y = "Number of countries",
       colour = "GrandBudapest")
Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.

ggplot(test) + 
  geom_histogram(aes(x=height), 
                 color='black', 
                 fill='salmon', 
                 breaks=unique(test$weight)) +
  theme(text = element_text(family="Times")) +
  labs(title = "Test Data",
       subtitle = "Year of 2022",
       caption = "Dummy data",
       tag = "Figure 2",
       x = "Height",
       y = "Number of people")

Synergy Report

Our team members worked collaboratively to produce these plots. The bar chart with varying widths was spearheaded by Vikrant and Namrta, and the facetted charts were primarily done by Eli and Seongdeok. Additionally, fonts were added by Vikrant; titles, captions, themes, colors, and axis labels were added by Lizzie; Eli merged these additions with the main plot code; and Namrta had the idea to use simple custom data to aid in plot creation.