Characteristics of Victims in family incident Crimes

Ge Zhang

2024-10-29

Introduction

This is an R Markdown presentation. 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.

Slide with Bullets

Slide with R Output

## 
## 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
## [1] "/Users/gezhang/Desktop/Semester2/visulization/A3/Data_Tables_Family_Incidents_Visualisation_Year_Ending_June_2024 2"

Slide with Plot

```{r,echo=FALSE} # Load required libraries library(ggplot2)

Plotting the line chart for total Family Incident Count by year

ggplot(data = incident_summary, aes(x = as.factor(Year), y = Total_Incidents, group = 1)) + geom_line(color = “steelblue”, size = 1) + geom_point(color = “red”, size = 2) + labs(title = “Total Family Incident Count Trend by Year”, x = “Year”, y = “Total Family Incident Count”) + scale_y_continuous(labels = scales::comma) + theme_minimal()


## 666

```{r,echo=FALSE }
library(ggplot2)
library(dplyr)

# load data
AFM_data <- read.csv("AFM-data.csv")

# ensure correct data type
AFM_data$Rate.per.100.000.population <- as.numeric(gsub(",", "", AFM_data$Rate.per.100.000.population))
AFM_data$Year <- as.factor(AFM_data$Year)
AFM_data$AFM.Age.Group <- as.factor(AFM_data$AFM.Age.Group)
AFM_data$AFM.Sex <- as.factor(AFM_data$AFM.Sex)

# group by sex
filtered_data <- AFM_data %>%
  filter(AFM.Sex %in% c("Females", "Males"))

# plot bar chart
ggplot(filtered_data, aes(x = AFM.Age.Group, y = Rate.per.100.000.population, fill = AFM.Sex)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Family violence victimization rate by gender and age group",
       x = "age gruop",
       y = "Rate.per.100.000.population",
       fill = "sex") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.title = element_blank())

777

```{r,echo=FALSE} # Read the data AFM_data <- read.csv(“AFM-data.csv”)

Filter data to get the total count for each gender

Convert the Rate column to numeric

AFM_data\(Rate.per.100.000.population <- as.numeric(gsub(",", "", AFM_data\)Rate.per.100.000.population))

Group by Sex and summarize the total victims count

victim_summary <- AFM_data %>% filter(AFM.Sex %in% c(“Females”, “Males”)) %>% group_by(AFM.Sex) %>% summarise(Total_Victims = sum(Rate.per.100.000.population, na.rm = TRUE))

ggplot(victim_summary, aes(x = ““, y = Total_Victims, fill = AFM.Sex)) + geom_bar(stat =”identity”, width = 1) + coord_polar(“y”, start = 0) + geom_text(aes(label = paste0(round(Total_Victims / sum(Total_Victims) * 100, 1), “%”)), position = position_stack(vjust = 0.5)) + labs(title = “Gender-wise Victim Count Proportion”, fill = “Gender”) + theme_void()

## 888

```{r,echo=FALSE}
install.packages("reshape2")
library(ggplot2)
library(reshape2)
# read the data
AFM_data <- read.csv("AFM-data.csv")

# ensure the correct data type
AFM_data$Rate.per.100.000.population <- as.numeric(gsub(",", "", AFM_data$Rate.per.100.000.population))
AFM_data$Year <- as.factor(AFM_data$Year)
AFM_data$AFM.Age.Group <- as.factor(AFM_data$AFM.Age.Group)

# Convert the data into a format suitable for creating a heatmap, using the mean as the aggregation function
heatmap_data <- dcast(AFM_data, AFM.Age.Group ~ Year, value.var = "Rate.per.100.000.population", fun.aggregate = mean)


# convert to long type
heatmap_long <- melt(heatmap_data, id.vars = "AFM.Age.Group", variable.name = "Year", value.name = "Rate")
print(heatmap_long)

# plot heatmap
ggplot(heatmap_long, aes(x = Year, y = AFM.Age.Group, fill = Rate)) +
  geom_tile(color = "white") +
  scale_fill_gradient(low = "#FEE0D2", high = "#DE2D26", na.value = "#F7F7F7") +
  labs(title = "Heatmap of family violence victimization rates across different age groups",
       x = "year",
       y = "age group",
       fill = "Rate.per.100.000.population") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

999

```{r,echo=FALSE} library(ggplot2)

Load the data

AFM_data <- read.csv(“AFM-data.csv”)

Ensure data types are correct

AFM_data\(Rate.per.100.000.population <- as.numeric(gsub(",", "", AFM_data\)Rate.per.100.000.population)) AFM_data\(Year <- as.factor(AFM_data\)Year) AFM_data\(AFM.Age.Group <- as.factor(AFM_data\)AFM.Age.Group)

Create boxplot to show the distribution of family violence victim counts by age group

ggplot(AFM_data, aes(x = AFM.Age.Group, y = Rate.per.100.000.population)) + geom_boxplot(fill = “#69b3a2”, color = “#1f2f56”) + labs(title = “Boxplot of Family Violence Victim Counts by Age Group”, x = “Age Group”, y = “Rate per 100,000 population”) + theme_minimal() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) ```