The purpose of this assignment is to create a web page using R Markdown that features a plot created with Plotly.
I’ve chosen to look at the trend of the average number of babies by woman in Oceania from 1958 to 2018 to check whether there is a general decrease as expected or not.
Data has been extracted from the following source: GAPMINDER.
The dataset used contains the average number of babies by woman for the years 1958, 1968, 1978, 1988, 1998, 2008 and 2018 for 9 countries in the Oceania continent.
Year | Australia | Fiji | Kiribati | Micronesia | New_Zealand | Papua_New_Guinea | Samoa | Tonga | Vanuatu |
---|---|---|---|---|---|---|---|---|---|
1958 | 3.42 | 6.74 | 6.70 | 6.98 | 3.56 | 6.27 | 7.65 | 7.35 | 7.33 |
1968 | 2.88 | 4.89 | 5.90 | 6.92 | 3.02 | 6.21 | 7.33 | 6.37 | 6.43 |
1978 | 1.97 | 3.97 | 5.06 | 6.40 | 2.19 | 5.84 | 6.43 | 5.51 | 5.72 |
1988 | 1.85 | 3.47 | 4.78 | 5.17 | 2.32 | 4.93 | 5.30 | 4.76 | 5.02 |
1998 | 1.77 | 3.17 | 4.17 | 4.47 | 1.96 | 4.60 | 4.59 | 4.30 | 4.54 |
2008 | 1.94 | 2.74 | 3.87 | 3.59 | 2.12 | 4.10 | 4.43 | 4.01 | 3.61 |
2018 | 1.83 | 2.47 | 3.57 | 3.05 | 1.97 | 3.56 | 3.88 | 3.56 | 3.20 |
df <- read.xlsx("./children_per_woman_total_fertility.xlsx",
sheet = 1, colNames = TRUE)
CountryList <- c("Australia", "Fiji", "Kiribati", "Micronesia",
"New_Zealand", "Papua_New_Guinea", "Samoa", "Tonga", "Vanuatu")
knitr::kable(x = df, booktabs = T, align = "ccc")
PLT <- plot_ly(data = df, x = ~Year)
for (k in 1:length(CountryList)) {
df_k <- data.frame(y = df[[CountryList[k]]], Year = df$Year)
PLT <- add_trace(PLT, y = ~y, x = ~Year, data = df_k, type = "bar",
name = CountryList[k])
}
PLT <- layout(PLT, title = "Children per Woman in Oceania\nTrend 1958-2018",
xaxis = list(type = "category", title = "", tickfont = list(size = 12,
color = "black")), yaxis = list(title = "Number of Children",
titlefont = list(size = 12, color = "black"), tickfont = list(size = 12,
color = "black")), barmode = "group", bargap = 0.15)
PLT