data <- data.melt.yearly %>% dplyr::filter(continent %in% c("Africa", "Asia", "Europe", "North America", "South America")) fig.education <- data %>% plotly::group_by(continent) %>% plotly::plot_ly(x = ~year, color = ~continent, colors = c('#E41A1C', '#377EB8', '#4DAF4A', '#984EA3', '#A65628'), legendgroup = ~continent, hovertext = paste("Education Discrepancy: ", data$education_discrepancy_avg, "<br>Year: ", data$year, "<br>Continent: ", data$continent), hoverinfo = "text") %>% plotly::add_lines(y = ~education_discrepancy_avg, showlegend = FALSE) %>% plotly::layout(xaxis = list(title = "Year"), yaxis = list(title = "Education Discrepancy")) fig.suicide <- data %>% plotly::group_by(continent) %>% plotly::plot_ly(x = ~year, color = ~continent, colors = c('#E41A1C', '#377EB8', '#4DAF4A', '#984EA3', '#A65628'), legendgroup = ~continent, hovertext = paste("Suicide: ", data$suicide_avg, "<br>Year: ", data$year, "<br>Continent: ", data$continent), hoverinfo = "text") %>% plotly::add_lines(y = ~suicide_avg) %>% plotly::layout(xaxis = list(title = "Year"), yaxis = list(title = "Suicide")) fig.babies <- data %>% plotly::group_by(continent) %>% plotly::plot_ly(x = ~year, color = ~continent, colors = c('#E41A1C', '#377EB8', '#4DAF4A', '#984EA3', '#A65628'), legendgroup = ~continent, hovertext = paste("Babies: ", data$babies_per_woman_avg, "<br>Year: ", data$year, "<br>Continent: ", data$continent), hoverinfo = "text") %>% plotly::add_lines(y = ~babies_per_woman_avg, showlegend = FALSE) %>% plotly::layout(xaxis = list(title = "Year"), yaxis = list(title = "Babies Per Woman")) fig.gini <- data %>% plotly::group_by(continent) %>% plotly::plot_ly(x = ~year, color = ~continent, colors = c('#E41A1C', '#377EB8', '#4DAF4A', '#984EA3', '#A65628'), legendgroup = ~continent, hovertext = paste("Gini Coefficient: ", data$gini_avg, "<br>Year: ", data$year, "<br>Continent: ", data$continent), hoverinfo = "text") %>% plotly::add_lines(y = ~gini_avg, showlegend = FALSE) %>% plotly::layout(xaxis = list(title = "Year"), yaxis = list(title = "Gini Coefficient")) fig <- plotly::subplot(fig.education, fig.suicide, fig.babies, fig.gini, nrows=2, titleY = TRUE, margin = c(0.085,0.01,0.1,0.1)) %>% plotly::layout(title = "Quality of Life over Time") fig
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.