0
votes

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
So, what is your question? :) I think in the graph, the axis labels of the year are exactly at 1st January of each year. That is why for instance December 18 is pretty close to the 2019 label. - otwtm
If you want the points just above the year name, then you probably don't want to use your datetime values on the x-axis, but a factor with values (2014,...2019) instead. - otwtm
Points are lying on the months which do not appear as labels on x-axis. - Parfait
@otwtm Yes the problem as I realise now is the data being displayed at individual months within each year. that may be the reason why points shift away from the year point in x-axis. What i wanted to do was to have every months data directly on the year name. - Basant

1 Answers

0
votes

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))