family violence

Ge

2024-10-29

R Markdown

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

# Load required libraries
library(ggplot2)
library(dplyr)
## 
## 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
getwd()
## [1] "/Users/gezhang/Desktop/Semester2/visulization/A3/Data_Tables_Family_Incidents_Visualisation_Year_Ending_June_2024 2"
#  data loading step
family_incidents_data <- read.csv("family-incidents-data.csv")

# Ensure correct data type for Family.Incident.Count
family_incidents_data$Family.Incident.Count <- as.numeric(gsub(",", "", family_incidents_data$Family.Incident.Count))

# Group data by Year and summarize total Family Incident Count
incident_summary <- family_incidents_data %>%
  group_by(Year) %>%
  summarise(Total_Incidents = sum(Family.Incident.Count, na.rm = TRUE))

# Plotting the bar chart for total Family Incident Count by year
ggplot(data = incident_summary, aes(x = as.factor(Year), y = Total_Incidents)) +
  geom_bar(stat = "identity", fill = "steelblue") +
  labs(title = "Total Family Incident Count by Year",
       x = "Year",
       y = "Total Family Incident Count") +
  scale_y_continuous(labels = scales::comma) +
  theme_minimal()

Slide with Plot

# 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()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.