0

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

data

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.

original data

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()  
Plecotus
  • 1
  • 1
  • I assume you've made it work. Next time though please provide a reproducible example instead of a screenshot of your data: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – william3031 Mar 17 '23 at 00:33
  • Apologies @william3031 it my first post so do not know now to attached data. Will try to up date later today. I did not get the extra points or line graphs (max,min)to work so still a open question – Plecotus Mar 17 '23 at 08:09

0 Answers0