I am trying to display three point and line graphs showing mean, min and max temperature on a dual axis bar plot showing Precipitation/Temperature for five nights perr month.
I have managed to get the bar and the first (mean temperature) points to show, but I can not get the geom_line or the additional points.
Night temperature and rainfall
Night %>%
mutate(Night = fct_reorder(Night,Order)) %>%
ggplot(aes(x= Night,y = Precip..Accum..Mm)) +
geom_col()+
geom_point(aes(y = a + Average.of.Temp*b), color = "red") +
#geom_point(aes(y = a + min.of.Temp*b),color ="blue")+
#geom_point(aes(y = a + max.of.Temp*b),color ="blue")+
#geom_line(aes(y = a + Average.of.Temp*b), color = "red")+
scale_y_continuous("Precipitation mm", sec.axis = sec_axis(~ (. - a)/b, name = "Temperature (C) ")) +
ggtitle("Night time temperatures and precipitation during monitoring period")+
theme(axis.line.y.right = element_line(color = "red"),
axis.ticks.y.right = element_line(color = "red"),
axis.text.y.right = element_text(color = "red"),
axis.title.y.right = element_text(color = "red"),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
theme_bw()
first post, so I don't know how to attach data image below if it helps
The line graph does not draw, nor does the extra geom_points. It would be great if I could get the line graph to show the Mean Temperature, but ideally, a point and line graph for max and min temperature would also be ideal.
I also originally intended to facet the plot with a combined data set, below. But could not get that even started.
any help is much appreciated.
Since posting, I managed to get the facet to work.
enter code here
a=0.2
b=1
Day_Night %>%
mutate(Night = fct_reorder(Night,Order)) %>%
ggplot(aes(x= Night,y = Precip..Accum..Mm)) +
geom_col()+
geom_point(aes(y = a + Mean*b), color = "red") +
#geom_point(aes(y = a + min.of.Temp*b),color ="blue")+
#geom_point(aes(y = a + max.of.Temp*b),color ="blue")+
#geom_line(aes(y = a + Average.of.Temp*b), color = "red")+
scale_y_continuous("Precipitation mm", sec.axis = sec_axis(~ (. -
a)/b, name = "Temperature (C) ")) +
geom_hline(yintercept=10,color ="red",linetype = "dashed")+
facet_grid(~DN)+
ggtitle("Day and Night time temperatures and precipitation during
monitoring period")+
theme(axis.line.y.right = element_line(color = "red"),
axis.ticks.y.right = element_line(color = "red"),
axis.text.y.right = element_text(color = "red"),
axis.title.y.right = element_text(color = "red"),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
theme_bw()