I am creating the distribution of irradiance in each month for the year 2014 to 2018. The graph for the first three months looks fine as the points lie in each year, then the data points slowly start to move right of the axis and by the time its December, the 2018 data is displayed in 2019 column.

I am a relatively new user in R and don't have much idea on what is going underneath. Here I attach my code and graphs. Month name was created through the simple command of Month <- months(a) from base library. Please help me with this.

ggplot(data = Weather_new, aes(x=DateAndTime, y= KP_sensor), na.rm=TRUE) + 
 geom_point(color = "darkblue", alpha=0.2)+
  facet_wrap(.~Monthnames, ncol=4, strip.position = "top")+
  labs(title = "Irradiance distribution over the years")+ xlab('Years')+ 
  ylab(expression("Irradiance"~"["*W / m^2*"]"))+
  theme(plot.title = element_text(face = "bold"))+
  theme(plot.title = element_text(hjust = 0.5))

**Image of Irradiance distribution overt the 5 years from 2014 to 2018**

1 Answers

0
Parfait On Best Solutions

Consider adding a year column and replace the datetime field as x value in aes:

Weather_new <- transform(Weather_new, Year = factor(format(DateAndTime, "%Y")))

ggplot(data = Weather_new, aes(x=Year, y= KP_sensor), na.rm=TRUE) + 
  geom_point(color = "darkblue", alpha=0.2) +
  facet_wrap(.~Monthnames, ncol=4, strip.position = "top") +
  labs(title = "Irradiance distribution over the years") +
  xlab('Years') + ylab(expression("Irradiance"~"["*W / m^2*"]")) +
  theme(plot.title = element_text(face = "bold")) +
  theme(plot.title = element_text(hjust = 0.5))