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)
# New data for CRIS vs EV CRIS
data <- data.frame(
Value = c(
"Asian",
"Urbanized (200,000+)",
"4 Or More Lanes, Undivided",
"Male",
"White",
"Rural Prin Arterial"
),
All_CRIS = c(3.448, 62.466, 29.057, 54.163, 37.273, 27.264),
EV_CRIS = c(22.239, 80.103, 37.932, 60.85, 43.959, 32.842)
)
# Convert to long format
data_long <- data %>%
pivot_longer(cols = c(All_CRIS, EV_CRIS),
names_to = "Group", values_to = "Percentage")
# Use numeric x-axis to control spacing
data_long$GroupX <- ifelse(data_long$Group == "All_CRIS", 1, 1.5)
# Get labels at the right (EV_CRIS)
labels_df <- data_long %>% filter(Group == "EV_CRIS")
# Plot
ggplot(data_long, aes(x = GroupX, y = Percentage, group = Value)) +
geom_line(aes(linetype = Value), color = "black", size = 1) +
geom_point(aes(shape = Value), color = "black", size = 3) +
geom_text(data = labels_df,
aes(label = Value),
hjust = 0, vjust = 0.5, size = 4.5,
fontface = "bold", color = "black") +
scale_x_continuous(
breaks = c(1, 1.5),
labels = c("All CRIS", "EV CRIS"),
expand = expansion(mult = c(0.01, 0.8))
) +
scale_linetype_manual(values = c("solid", "dashed", "dotdash", "twodash", "longdash", "twodash")) +
scale_shape_manual(values = c(15, 16, 17, 18, 3, 4)) +
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.
