How to show both bars for both of my categories as a stacked bar plot? The taller bars are covering up the shorter ones when I want to just show both on top of each other.
My code:
ylim.prim <- c(0,850) # scale for precipitation
ylim.sec <- c(-15,20) # scale for mean temperature
b <- diff(ylim.prim)/diff(ylim.sec)
a <- ylim.prim[1] - b*ylim.sec[1]
ggplot() + theme_bw() +
geom_bar(data=appended, aes(x=Year, y=PrecipA), fill="lightcoral", stat="identity",linewidth=1) +
geom_bar(data=appended, aes(x=Year, y=PrecipB),fill="lightblue",stat="identity", linewidth=1) +
geom_point(data=appended, aes(y=a+TempA*b, x=Year, fill=TempA, color="Active"), size=5, shape=18) +
geom_point(data=appended, aes(y=a+TempB*b, x=Year, fill=TempB, color="Non-Active"), size=5, shape=18) +
# Borders for point data
geom_point(data=appended, aes(y=a + TempA*b, x=Year), color="black", size=3, shape=5, stroke=2) +
geom_point(data=appended, aes(y=a + TempB*b, x=Year), color="black", size=3, shape=5, stroke=2) +
scale_y_continuous(name="Total Precipitation (mm) n", breaks=c(100,200,300,400,500,600,700,800,900), limits=c(0,900),
sec.axis = sec_axis(~(. - a)/b, name = "Mean Temperature (°C)")) +
scale_x_continuous(name="nYear") +
theme(axis.text.x = element_text(size=15, colour="black"),
axis.text.y = element_text(size=15, colour="black"),
axis.title = element_text(size=15),
axis.title.y = element_text(size=15),
legend.text = element_text(size=15),
legend.title = element_text(size=15),
axis.title.y.right = element_text(angle=90))
> dput(appended)
structure(list(Year = 2020:2023, TempA = c(17.081043956044, 17.6239554317549,
17.1328402366864, 17.3330578512397), PrecipA = c(737, 789.8,
611.3, 802.7), TempB = c(3.2175, 3.48527777777778, 1.54847645429363,
3.79614325068871), PrecipB = c(805, 612.8, 710.5, 753.5)), row.names = c(NA,
-4L), class = "data.frame")
My figure so far: