Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中绘制一周中几天的图表_R_Plot - Fatal编程技术网

在R中绘制一周中几天的图表

在R中绘制一周中几天的图表,r,plot,R,Plot,我的数据框中有一列名为date,另一列名为values。我想根据一周中的几天来绘制这些值 我知道,通过使用函数weekdays(),我们可以从date开始计算一周中的天数。但是我不确定如何用值(y轴)和一周中的几天(x轴)绘制图表 我试过这个 plot(weekdays(df$Date),df$values) 我得到了这个错误: Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages

我的数据框中有一列名为
date
,另一列名为
values
。我想根据一周中的几天来绘制这些值

我知道,通过使用函数
weekdays()
,我们可以从date开始计算一周中的天数。但是我不确定如何用
值(y轴)和一周中的几天(x轴)绘制图表

我试过这个

plot(weekdays(df$Date),df$values)
我得到了这个错误:

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

有人能帮我纠正这个错误吗?

在绘图之前,您必须将
工作日(df$date)
更改为一个因子

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

df$Date我认为您的日期列格式不正确。试着事先用
df$Date更改它,我已经在代码中这样做了。当我尝试绘图时,错误仍然存在。当您运行
类(工作日(df$Date))
时,您会注意到它属于
字符类。您需要将其转换为因子或有序因子。因此,运行此代码
plot(as.factor(工作日(df$Date)),df$value)
将根据需要绘制图形。您可以使用
levels
重新排列级别,使其达到正确的顺序。
df$Date <- as.factor(weekdays(df$Date))