@@ -7,3 +7,78 @@ library(waffle)
7
7
library(hrbrthemes )
8
8
library(ggalt )
9
9
library(GGally )
10
+ library(ggimage )
11
+
12
+ font_add_google(" Playfair Display" , " Playfair" )
13
+ font_add_google(' Fira Sans' , ' firasans' )
14
+ showtext_auto()
15
+
16
+ df = read.csv(" ../input/world-happiness-report-2021/world-happiness-report-2021.csv" )
17
+
18
+ df_cor <- df %> %
19
+ select(Corruption = Perceptions.of.corruption ,
20
+ Generosity = Generosity ,
21
+ Freedom = Freedom.to.make.life.choices ,
22
+ Life_Expectancy = Healthy.life.expectancy ,
23
+ Social_Support = Social.support ,
24
+ GDP_Per_Capita = Logged.GDP.per.capita ,
25
+ Happiness = Ladder.score
26
+ )
27
+
28
+ my_theme <- function () {
29
+
30
+ # Colors
31
+ color.background = " #FFFFFF"
32
+ color.text = " #FFFFFF"
33
+
34
+ # Begin construction of chart
35
+ theme_bw(base_size = 15 ) +
36
+
37
+ # Format background colors
38
+ theme(panel.background = element_rect(fill = color.background , color = color.background )) +
39
+ theme(plot.background = element_rect(fill = color.background , color = color.background )) +
40
+ theme(panel.border = element_rect(color = color.background )) +
41
+ theme(strip.background = element_rect(fill = color.background , color = color.background )) +
42
+ # Format the grid
43
+ theme(panel.grid.major.y = element_blank()) +
44
+ theme(panel.grid.minor.y = element_blank()) +
45
+ theme(panel.grid.major.x = element_blank())+
46
+ theme(panel.grid.minor.x = element_blank()) +
47
+ theme(axis.ticks = element_blank()) +
48
+
49
+ # Format the legend
50
+ theme(legend.position = " none" ) +
51
+
52
+ # Format title and axis labels
53
+ theme(plot.title = element_text(color = color.text , size = 40 , face = " bold" , hjust = 0.5 , family = ' Playfair' ))+
54
+ theme(plot.subtitle = element_text(color = color.text , size = 30 , face = " bold" , hjust = 0.5 , family = ' Playfair' ))+
55
+ theme(plot.caption = element_text(color = color.text , size = 20 , face = " bold" , hjust = 0.5 , family = ' firasans' ))+
56
+ theme(axis.title.x = element_blank()) +
57
+ theme(axis.title.y = element_blank()) +
58
+ theme(axis.text.x = element_text(size = 17 , color = color.text , hjust = 0.5 , vjust = 0.5 ,face = " bold" , family = ' firasans' )) +
59
+ theme(axis.text.y = element_text(size = 17 , color = color.text , face = " bold" , family = ' firasans' )) +
60
+ theme(strip.text = element_text(face = " bold" )) +
61
+
62
+ # Plot margins
63
+ theme(plot.margin = unit(c(0.35 , 0.2 , 0.3 , 0.35 ), " cm" ))
64
+ }
65
+
66
+ p1 <- ggcorr(df_cor ,
67
+ method = c(" everything" , " pearson" ),
68
+ size = 10 , hjust = 0.77 ,
69
+ fontface = " bold" ,
70
+ family = ' Playfair' ,
71
+ color = ' white' ,
72
+ label = TRUE , label_size = 15 ,
73
+ layout.exp = 1 ) +
74
+ scale_fill_paletteer_c(" grDevices::Mint" )+
75
+ my_theme()+
76
+ annotate(" text" , x = 4 , y = 6 , label = " Happiness most strongly correlates with \n (1) wealth(GDP) \n (2) health, \n (3) social support, \n (4) freedom'" , size = 15 , family = ' lora' , color = ' white' )+
77
+ labs(title = ' Which Factors Most Strongly Correlate With Happiness' ,
78
+ subtitle = " World Happiness Report 2021" ,
79
+ caption = " Data Source : https://www.kaggle.com/datasets/ajaypalsinghlo/world-happiness-report-2021" )
80
+ p1
81
+
82
+ url <- " https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse3.mm.bing.net%2Fth%3Fid%3DOIP.wbTIFSSicsbig448lcENyQHaEo%26pid%3DApi&f=1"
83
+ ggbackground(p1 , url )
84
+
0 commit comments