>dates
"2020-10-03" "2020-10-04" "2020-10-21"
>class(dates)
[1] "Date"
values= c(110,90,90)
cols=ifelse(values>=0,"green","red")
barplot(height = values, width = dates,col = cols, xlab = "values") # error here
Ops.Date(space,mean(width)) 中的错误:* 未为“Date”对象定义
最佳答案
更简单的选择是公式
方法
barplot(values ~ dates, col = cols, xlab = "values")
-输出
根据?barplot
,'height'、'width'都是向量
,Date
是一个带有一些属性的向量。因此,如果我们使用 as.numeric
转换为 vector
,它将起作用
barplot(height = values, width = as.numeric(dates),col = cols, xlab = "values")
数据
dates <- structure(c(18538, 18539, 18556), class = "Date")
关于r - 如何将日期放在 barplot() x Axis 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64489144/