Reputation: 1029
I have a dataset consisting Date, maximum value, minimum value
and the average.
I want to plot the average
value against the Date.
I am using ggplot2
for this purpose.
This is the code I am using:
ggplot(Data, aes(Date, Avg)) +
geom_point()
The plot from this code is showing several x-axis grid lines. It is plotting gridlines one for each day. But, this is not what I want.
I want to plot one grid line for one month. Lets say, the first grid line for 1st Jan, ... 12th grid for 1st Dec.
However, I am aware of assigning a new column consisting of dates, by using the following command:
seq(as.Date("2013-01-01"), as.Date("2013-12-31"), by=1)
but I want to manipulate the number of grids as per my requirement.
Thanks in advance.
Upvotes: 1
Views: 171
Reputation: 19867
You can set ticks intervals on an axis with dates values with the option breaks
in scale_x_datetime
/ scale_y_datetime
. Here:
ggplot(Data, aes(Date, Avg)) +
geom_point() +
scale_x_date(breaks = "1 month")
Upvotes: 1