1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| options(repr.plot.width=10,repr.plot.height=8)
seasonal_df$season <- ifelse(seasonal_df$month %in% c("03","04","05"),"Spring", ifelse(seasonal_df$month %in% c("06","07","08"),"Summer", ifelse(seasonal_df$month %in% c("09","10","11"),"Autumn","Winter")))
seasonality_plot_conventional_price <- seasonal_df %>% select(season,year,average_price,type) %>% filter(type =="conventional") %>% group_by(season,year) %>% summarise(avg=mean(average_price)) %>% ggplot(aes(x=season,y=avg,color=season))+ geom_segment(aes(x=season,xend=season,y=0,yend=avg),show.legend = FALSE)+ coord_flip()+ facet_wrap(~as.factor(year))+ theme_minimal()+ theme(plot.title = element_text(hjust = 0.5),plot.background = element_rect(fill="#F4F6F7"))+ labs(title = "Conventional Avocados average price by Season",x="",y="Average price")+ geom_text(aes(x=season,y=0.01,label=paste0("$ ",round(avg,2))),hjust=-0.5,vjust=-0.5,size=4,color="black",fontface='italic',angle=360)
seasonality_plot_conventional_volume <- seasonal_df %>% select(season,year,total_volume,type) %>% filter(type=="conventional") %>% group_by(season,year) %>% summarise(avg=round(mean(total_volume/1000000),2)) %>% ggplot(aes(x=season,y=avg,color=season))+ geom_segment(aes(x=season,xend=season,y=0,yend=avg),show.legend = FALSE)+ coord_flip()+ facet_wrap(~as.factor(year))+ theme_minimal()+ theme(plot.title = element_text(hjust = 0.5),plot.background = element_rect(fill="#F4F6F7"))+ labs(title = "Conventional Avocados total volume by Season",x="",y="Average volume")+ geom_text(aes(x=season,y=0.01,label=paste0(avg," m")),hjust=-0.5,vjust=-0.5,size=4,color="black",fontface='italic',angle=360)
seasonality_plot_organic_price <- seasonal_df %>% select(season,year,average_price,type) %>% filter(type =="organic") %>% group_by(season,year) %>% summarise(avg=mean(average_price)) %>% ggplot(aes(x=season,y=avg,color=season))+ geom_segment(aes(x=season,xend=season,y=0,yend=avg),show.legend = FALSE)+ coord_flip()+ facet_wrap(~as.factor(year))+ theme_minimal()+ theme(plot.title = element_text(hjust = 0.5),plot.background = element_rect(fill="#F4F6F7"))+ labs(title = "Organic Avocados average price by Season",x="",y="Average price")+ geom_text(aes(x=season,y=0.01,label=paste0("$ ",round(avg,2))),hjust=-0.5,vjust=-0.5,size=4,color="black",fontface='italic',angle=360)
seasonality_plot_organic_volume <- seasonal_df %>% select(season,year,total_volume,type) %>% filter(type=="organic") %>% group_by(season,year) %>% summarise(avg=round(mean(total_volume/1000000),2)) %>% ggplot(aes(x=season,y=avg,color=season))+ geom_segment(aes(x=season,xend=season,y=0,yend=avg),show.legend = FALSE)+ coord_flip()+ facet_wrap(~as.factor(year))+ theme_minimal()+ theme(plot.title = element_text(hjust = 0.5),plot.background = element_rect(fill="#F4F6F7"))+ labs(title = "Organic Avocados total volume by Season",x="",y="Average volume")+ geom_text(aes(x=season,y=0.01,label=paste0(avg," m")),hjust=-0.5,vjust=-0.5,size=4,color="black",fontface='italic',angle=360)
plot_grid(seasonality_plot_conventional_price,seasonality_plot_organic_price,seasonality_plot_conventional_volume,seasonality_plot_organic_volume,nrow = 2,ncol = 2,labels = c("A","B","C","D"))
|