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
library(tidyr)
# Sample data
data <- data.frame(
Attribute = c("Dark - Not Lighted", "Dark - Lighted",
"Not an Intersection", "Yes, Exceeded Speed Limit"),
All_FARS = c(25.45, 21.003, 70.985, 7.089),
Both_Drug_Alc = c(37.271, 30.072, 77.158, 12.387)
)
# Convert to long format for ggplot
data_long <- data %>%
pivot_longer(cols = c(All_FARS, Both_Drug_Alc),
names_to = "Group", values_to = "Percentage")
# Clean group names
data_long$Group <- factor(data_long$Group,
levels = c("All_FARS", "Both_Drug_Alc"),
labels = c("All FARS", "Both Drug/Alcohol"))
# Prepare label positions at the 'Both Drug/Alcohol' side
labels_df <- data_long %>%
filter(Group == "Both Drug/Alcohol")
# Plot
ggplot(data_long, aes(x = Group, y = Percentage, group = Attribute)) +
geom_line(aes(linetype = Attribute), color = "black", size = 1) +
geom_point(aes(shape = Attribute), color = "black", size = 3) +
geom_text(data = labels_df,
aes(label = Attribute),
hjust = -0.05, vjust = 0.5, size = 4.5,
fontface = "bold", color = "black") +
scale_linetype_manual(values = c("solid", "dashed", "dotdash", "twodash")) +
scale_shape_manual(values = c(15, 16, 17, 18)) +
scale_x_discrete(expand = expansion(mult = c(0.1, 1.00))) +
labs(
title = " ",
x = "",
y = "Percentage",
caption = " "
) +
theme_minimal(base_size = 14) +
theme(
legend.position = "none",
plot.title = element_text(face = "bold")
)
## 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.
