This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
setwd("C:/Users/XJimm/Desktop/Study/Semester 2/Data VisuAL/A3")
library(readr)
## Warning: package 'readr' was built under R version 4.1.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.1.3
##
## 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
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.4 v stringr 1.4.0
## v tidyr 1.1.4 v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.1.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(magrittr)
## Warning: package 'magrittr' was built under R version 4.1.3
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
##
## set_names
## The following object is masked from 'package:tidyr':
##
## extract
library(ggplot2)
library(plotly)
## Warning: package 'plotly' was built under R version 4.1.3
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(knitr)
## Warning: package 'knitr' was built under R version 4.1.3
gender <- read.csv("male-vs-female-suicide.csv")
gender %>% head()
## Entity Code Year Male.suicide.rate..age.standardized.
## 1 Abkhazia OWID_ABK 2015 NA
## 2 Afghanistan AFG 1990 14.75
## 3 Afghanistan AFG 1991 14.81
## 4 Afghanistan AFG 1992 14.80
## 5 Afghanistan AFG 1993 15.02
## 6 Afghanistan AFG 1994 15.34
## Female.suicide.rate..age.standardized. Continent
## 1 NA Asia
## 2 5.46
## 3 5.43
## 4 5.38
## 5 5.41
## 6 5.50
cost <- read.csv("rogs-2020-parte-section13-dataset.csv")
cause <- read.csv("annual-number-of-deaths-by-cause.csv")
# Cause of death
# Suicide in young people 15-19 years old
# Cause of depression
#Hospital
Crude_Suicide_Rates <- read.csv("Crude Suicide rates.csv")
SR <- Crude_Suicide_Rates %>% select(c("Indicator", "Location", "Period", "Dim1", "FactValueNumeric","Dim2" ))
SRAus <- SR %>% filter(Location == "Australia")
popGH <- aggregate(formula = FactValueNumeric ~ Dim1 + Dim2, data = SRAus, FUN = sum)
popGH <- with(popGH, popGH[order(Dim1,Dim2),])
popGH <- popGH[,c("FactValueNumeric","Dim1","Dim2")]
popGH1 <- popGH %>% filter(Dim1 != c("Both sexes"))
colnames(popGH1) <- c("Crude_Suicide_Rate", "Gender", "Age")
popGH1$Crude_Suicide_Rate <- ifelse(popGH1$Gender == "Male", -1*popGH1$Crude_Suicide_Rate, popGH1$Crude_Suicide_Rate)
pyramidGH2 <- ggplot(popGH1, aes(x = Age, y = Crude_Suicide_Rate, fill = Gender)) +
geom_bar(data = subset(popGH1, Gender == "Female"), stat = "identity") +
geom_bar(data = subset(popGH1, Gender == "Male"), stat = "identity") +
scale_y_continuous(labels = paste0(as.character(c(seq(2, 0, -1), seq(1, 2, 1))), "")) +
coord_flip()
depression <- read.csv("Estimated Population-based prevalence of depression.csv")
depression1 <- depression %>% select(c("Indicator","Location", "SpatialDimValueCode", "FactValueNumeric"))
colnames(depression1) <- c("Indicator", "Location", "CODE", "Depression Rate")
library(plotly)
fig <- plot_ly(depression1, type='choropleth', locations=depression1$CODE, z=depression1$`Depression Rate`, text=depression1$Location, colorscale="Purples")%>%
layout(title = "Estimated population-based prevalence of depression - WHO data 2015")
fig
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.