ggplot2 - climatograph with R and ggplot -
i climatographe or climat chart using ggplot.
my data
> data.df mese temperatura.media pioggia 1 jan -0.3 46.6 2 feb 2.6 40.9 3 mar 7.1 68.5 4 apr 11.5 72.5 5 may 15.6 92.0 6 jun 19.1 79.6 7 jul 21.4 79.2 8 aug 20.6 81.2 9 sep 17.2 85.4 10 oct 11.3 98.9 11 nov 4.9 93.7 12 dec 0.8 52.1
i have
data.df$mese<-month(data.df$mese, label = t) climagg<-ggplot(data=data.df)+ geom_bar(aes(x=mese, y=pioggia),stat = "identity") climagg
that give me
but need have 2 axes 1 left , 1 right different range (e.g. climatographe)... it seem not easy ggplot.
so climat chart may easyer ... non axes , using multiplot fonction ggplot
ggtheme<-theme(strip.text.x = element_text(size=14), strip.text.y = element_text(size=14), legend.title = element_text(size=14), panel.background = element_blank() ) pioggiagg<-ggplot(data=data.df)+ geom_bar(aes(x=mese.asdate, y=pioggia),stat = "identity",fill="#67a9cf")+ geom_text(aes(x=mese.asdate, y=pioggia+3, label=pioggia),size=4)+ theme(axis.text.y=element_blank(), axis.title.y = element_blank(), axis.ticks = element_blank(), axis.title.x = element_text(face="bold", size=12))+ scale_x_discrete("")+ ggtheme pioggiagg tempgg<-ggplot()+ geom_bar(data=data.df,aes(x=mese.asdate, y=pioggia),stat = "identity",alpha=0)+ geom_bar(data=data.df,aes(x=mese.asdate, y=temp_max),stat = "identity",alpha=0)+ geom_bar(data=data.df,aes(x=mese.asdate, y=temp_mini),stat = "identity",alpha=0)+ geom_rect(data=data.df,stat = "identity",aes(xmin=mese-0.4, xmax=mese+0.4,ymin=temp_mini, ymax=temp_max),fill="#ef8a62")+ geom_text(data=data.df,aes(x=mese.asdate, y=temp_mini-3, label=temp_mini),size=4)+ geom_text(data=data.df,aes(x=mese.asdate, y=temp_max+3, label=temp_max),size=4)+ theme(axis.title.x = element_blank(), axis.title.y = element_blank(), axis.ticks = element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank())+ ggtheme tempgg multiplot(tempgg,pioggiagg,cols=1)
that give me
Comments
Post a Comment