I have a script in R that is doing a print of graphics automatically in form of a loop. I try to implement into the ggplot an annotation using annotate. But it doesn't work.
Here's the code:
sp<-ggplot(data=suche,aes(x=Datum)) +
ggtitle(paste("Temperatur und Niederschlag im Jahr ",year_s))+
geom_col(aes(y=Reg*10/30), fill="deepskyblue1")+
geom_bar(mapping=aes(y=Reg*10/30), stat="identity",
fill="deepskyblue1")+
geom_text_repel(aes(y=Reg*10/3`0, label=Reg), vjust=-0.3, size=3.5)+
theme_minimal()+
geom_point(aes(y=MinT)) +
geom_line(aes(y=MinT,group=1),color="blue", size=1)+
geom_point(aes(y=MitT)) +
geom_line(aes(y=MitT,group=1),color="green", size=1)+
geom_point(aes(y=MaxT)) +
geom_line(aes(y=MaxT,group=1),color="red", size=1)+
annotate("text", fontface="bold", hjust="left", size=2.5, x = 1, y = 28)
label = paste("Temperaturmittel:", as.character(mean(tx$MitT),"°C"))
geom_text_repel(aes(y=MinT, label=MinT), direction="both", hjust=0.5, vjust=-0.5, size=3)+
geom_text_repel(aes(y=MaxT, label=MaxT), direction="both", hjust=0.5, vjust=-0.5, size=3)+
geom_text_repel(aes(y=MitT, label=MitT), direction="both", size=3)+
scale_y_continuous(
name=expression("Temperatur in °C"), limits=c(smin,smax), breaks=seq(-20,100,5),
sec.axis=sec_axis(~.*30/10, breaks=seq(0,150,10),
name="Niederschlag [mm]"))+
theme_bw(base_size = 12)+
theme(plot.title = element_text(size = 12, face = "bold"))+
theme(axis.text.y=element_text(size = 10, face="bold"))
I tried to use the annotate inside ggplot but I get the error:
Error: Invalid input: date_trans works with objects of class Date only
So the "annotate" doesn't work here. My data is a dataframe already in date format, but how to define on the x-axis that a certain annotation appears at the graphic always on the 7th month of a certain year? YYYY-07-DD