Has anyone get any advise on how to make this look plot better?
library(ggplot2)
data1 <- c(280, 577, 363, 307)
data2 <- c(584, 493, 1188, 1017)
category <- c("2019", "2020", "2021", "2022")
category <- factor( category, levels = category )
df1 <- data.frame(category,
data1 = data1,
data2 = data2)
library(reshape2)
df1_melted <- melt(df1, id.vars = "category")
p <- ggplot(df1_melted, aes(x = category, y = value, fill = variable)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Number and Duration of CSO Spills into the Porter Brook",
x = "Year",
y = "Number of Spills",
fill = "Year") +
theme(plot.title = element_text(hjust = 0.5, vjust = 0.5)) +
scale_y_continuous(sec.axis = sec_axis(~ . + 0, name = "Duration (Hours)")) +
scale_fill_discrete(name = "", labels = c("Number of Spills", "Duration in Hours")) +
theme(legend.position = "bottom")
p
The barplot depicts the number and duration of Combined Sewer Overflow spills into a river. It doesn't look to bad as it is but I was wondering how I could optimise it? Such as formatting the axis to look better.
Any advice would be greatly appreciated. Thank you.
For example, I've been trying to figure out how to format the Y-axix using:
expand_limits(x = 0, y = 0) + coord_cartesian(expand = FALSE)
but I can't get it to work.
Similarly, I've tried to label the axis values to correspond with values (0-1200 for Duration)
Thank you.