I don't know how to do this with ggpubr but here is a solution with ggplot2
df <- read.csv("data.csv")
library(ggplot2)
reorder_within <- function(x, by, within, fun = mean, sep = "___", ...) {
new_x <- paste(x, within, sep = sep)
stats::reorder(new_x, by, FUN = fun)
}
scale_y_reordered <- function(..., sep = "___") {
reg <- paste0(sep, ".+$")
ggplot2::scale_y_discrete(labels = function(x) gsub(reg, "", x), ...)
}
ggplot(df, aes(x = crime_percent, y = reorder_within(Year, desc(crime_percent), Primary.Type))) +
geom_point(color="orange", size=2) +
geom_segment(aes(x=0,
xend=crime_percent,
yend=reorder_within(Year, desc(crime_percent), Primary.Type)),
color="grey") +
scale_y_reordered() +
labs(x="Type of Criminal Activity",
y="Crime Percent",
title="Yearly Trend of Different types of Crimes on Streets of Chicago") +
facet_wrap(vars(Primary.Type), scales = "free_y") +
theme(strip.text.x = element_text(size = 5))