Plotting versus days of the week in R

I have a column with a name datein my data frame and in another column with a name values. I want to calculate values ​​against days of the week.

I know that we can get the days of the week from the date using the function weekdays(). But I'm not sure how to plot the chart with values(y axis) in relation to the days of the week (x axis)

      Date  Values
12-03-2006     0.5
14-03-2006     0.6
18-03-2006     0.9
23-03-2006     1.1
02-04-2006     2.1

I tried this

plot(weekdays(df$Date),df$values)

I got this error:

Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

Can someone help me fix this error?

+4
source share
1 answer

You need to change weekdays(df$date)by a factor before you enter it.

df$Date <- as.factor(weekdays(df$Date))

will make it a factor, and therefore, you can use it to plot. plot(df$Date,df$Values)

+3
source

All Articles