library(tidyverse) #installs tidyverse package
## Warning: package 'tidyverse' was built under R version 4.0.4
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.0.5 v dplyr 1.0.3
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(dplyr) #installs dplyr package
setwd("C:/Users/Dano/Documents/") #sets working directoy
Violence <- read_csv("Violencedata.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## RecordID = col_double(),
## Country = col_character(),
## Gender = col_character(),
## `Demographics Question` = col_character(),
## `Demographics Response` = col_character(),
## Question = col_character(),
## `Survey Year` = col_character(),
## Value = col_double()
## )
# uploads data
violence1 <- na.omit(Violence) #removes missing values
names(violence1) <- gsub(" ","_",names(violence1)) # replaces spaces in headings with underscore
violence_onereason = filter(violence1, Demographics_Response %in% c("Higher", "No education"), Question %in% c("... for at least one specific reason" ) ) # this is to select ALL rows that have higher or no education, also selects all females and males that have higher or no education. This is the main targeted group that I want to study and compare.
violence_onereason1 = filter(violence_onereason, Demographics_Response %in% c("Higher"), Question %in% c("... for at least one specific reason" ) ) # this is to select all rows that have only higher education that belong to the group that agree that a husband is justified in hitting or beating his wife for at least one specific reason
violence_onereason1 %>%
ggplot() +
geom_boxplot(aes(x = Gender, y=Value, group=Gender,fill=Gender)) +
labs(title="Percentage Of Respondents With Higher Education Who Agree That A Husband Is
Justified In Hitting Or Beating His Wife For At Least One Specific Reason" ,x="Gender", y = "Percentage")+ scale_fill_brewer(palette="Dark2") +
theme_classic() + scale_x_discrete(labels=c("Female", "Male"))+ theme(legend.position = "none") #this creates a boxplot with title and classic them and splits the higher education groups into females versus males.
violence_onereason2 = filter(violence_onereason, Demographics_Response %in% c("No education"), Question %in% c("... for at least one specific reason" ) ) # this is to select all rows that have "no education" as demographic response which selects all females and males with no education. This another targeted groups that I want to analyze.
violence_onereason2 %>%
ggplot() +
geom_boxplot(aes(x = Gender, y=Value, group=Gender,fill=Gender)) +
labs(title="Percentage Of Respondents With No Education Who Agree That A Husband Is
Justified In Hitting Or Beating His Wife For At Least One Specific Reason" ,x="Gender", y = "Percentage")+ scale_fill_brewer(palette="Dark2") +
theme_classic() + scale_x_discrete(labels=c("Female", "Male")) + theme(legend.position = "none") #this creates a boxplot with title and classic them and splits the the no education groups into females versus males.
library(readr)
library(ggplot2)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
library(highcharter)
## Warning: package 'highcharter' was built under R version 4.0.4
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(RColorBrewer)
#installs highcharter packages that are needed to create highcharter graphs
#I now want to compare all countries females and male respondents that have higher education
violence_onereasonhec <- filter(violence1, Demographics_Response %in% c("Higher"), Question %in% c("... for at least one specific reason" ))
#this is to select all rows that have higher education which selects all female and male respondents
cols <- brewer.pal(4, "Set2") #sets color palette
graph1 <-violence_onereasonhec[order(-violence_onereasonhec$Value),]
graph1 %>%
hchart("bar", hcaes(x= Country, y = Value, group = Gender), name=c("Female", "Male")) %>% #command for bar plot graph
hc_title(text = "Respondents With Higher Education",
style = list(fontWeight = "bold", fontSize = "14px"),
align = "center") %>% #command for title and subtitle
hc_subtitle(text = "Percentage of Respondents Who Agree That A Husband Is Justified In Beating His Wife For At Least One Specific Reason",
align = "center") %>%
hc_xAxis(title = list(text = "Countries"))%>%
hc_yAxis(title = list(text = "Percentage of Respondents "), minorTickInterval = "auto") %>% #sets axis titles
hc_size(height=1300,width=600) %>% #elongates graph vertically so that all countries show up on the graph
hc_add_theme(hc_theme_google()) %>% #sets the google theme for this graph
hc_legend(align = "right",
verticalAlign = "top") %>% #modifies legend
hc_colors(cols) %>%
hc_tooltip(pointFormat="<b>{point.Gender}</b>: {point.Value}%")#adds color to graph
#I now want to compare all countries for all female and male respondents with no education
violence_onereasonne <- filter(violence1, Demographics_Response %in% c("No education"), Question %in% c("... for at least one specific reason" )) # this is to select all rows that have no education which selects all females and males.
cols <- brewer.pal(4, "Set2") #sets color palette
graph2 <-violence_onereasonne[order(-violence_onereasonne$Value),]
options(repr.plot.width = 8, repr.plot.height = 9)
graph2 %>%
hchart("bar", hcaes(x= Country, y = Value, group = Gender), name=c("Female", "Male")) %>% #bar plo graph command
hc_title(text = "Respondents with No Education",
style = list(fontWeight = "bold", fontSize = "14px"),
align = "center") %>% #adds title and subtitle for graph
hc_subtitle(text = "Percentage Of Respondents Who Agree That A Husband Is Justified In Beating His Wife For At Least One Specific Reason",
align = "center") %>%
hc_xAxis(title = list(text = "Countries"))%>%
hc_yAxis(title = list(text = "Percentage Of Respondents "), minorTickInterval = "auto")%>% #adds axis title
hc_size(height=1300,width=600) %>% #elongates graph vertically so that all countries show up
hc_add_theme(hc_theme_google()) %>% #adds google theme
hc_legend(
align = "right",
verticalAlign = "top", legend=c("Line 1", "Line 2"),
title=("Line types")) %>% #adds legend to the right side of the graph
hc_colors(cols)
https://public.tableau.com/views/GenderViolenceMap/GenderViolenceMap?:language=en&:display_count=y&publish=yes&:origin=viz_share_link