回答
像这样的事情会做到这一点:
# load data:
theData = read.csv2(file = "sample.csv",header = TRUE,
stringsAsFactors = FALSE,sep = ",",
colClasses = c("character",rep("numeric",5)),dec=".")
# We want to plot a custom x-axis, so stop the default
# x-axis being drawn usign xaxt="n":
plot(theData$CLOSE,type="l",xaxt="n")
# Lets say you want to put a date label in 8 different locations:
locations = floor(seq(from=1,to=nrow(theData),by=nrow(theData)/8))
# Now draw the x-axis on your plot like this:
axis(side = 1, at = locations, labels=theData$DATE[locations],las=2)
在上面,side=1
意味着底部绘制轴。 at=locations
表示我们想要在我们之前创建的位置向量中给出的位置显示刻度标签。 labels=theData$DATE[locations]
提供了我们想要放置在我们放置标签的位置的标签。 las=2
表示您想要旋转刻度标签。尝试las=1
以及不同的旋转。
然而,这些日期是那种长,所以你可能需要创建更小的日期是这样的:
# Convert your long dates to smaller dates like YYYY-MM-DD, and stick
# the results to the end of your data frame.
theData = cbind(theData,
"FormattedDate"=as.Date(theData$DATE,"%A, %B %e, %Y"))
# Replot and use your smaller dates. (ces.axis=0.8 makes
# the font smaller)
plot(theData$CLOSE,type="l",xaxt="n")
axis(side = 1, at = locations,
labels=theData$FormattedDate[locations],las=1,cex.axis=0.8)
最后,您还可以使用一些美好的时光套餐系列能够轻松地创建更漂亮地块:
install.packages("xts")
library(xts)
xtsData = xts(theData[,"OPEN"],order.by = theData[,"FormattedDate"])
plot.zoo(xtsData)
# or
plot.xts(xtsData)
非常感谢。 –
尝试使用
dataset$DATE<-.as.POSIXct(dataset$DATE)
这是R消息 datatest $ DATE = as.POSIXct(datatest $ DATE) as.POSIXlt.character(as.character(x),...)中的错误: 字符串不是标准的明确格式' –
如果我在文件csv中更改为短日期格式,那么我如何将DATE变量添加到时间序列图中? –
dataset$DATE <- as.Date(dataset$DATE, format = "%A, %B %d, %Y")
- %A - 长平日
- %B - 完整的月份名称
- %d - 两位数日期
- %Y - 四位数年份
- 1. 时间序列绘制在R
- 2. 用图例绘制R中的倍数(时间)系列
- 3. 在R中绘制时间序列图R
- 4. 在R中绘制箱形图和一系列时间序列数据
- 5. 使用R绘制时间序列
- 6. 在R中绘制数据和时间
- 7. 如何在R中绘制二进制状态时间序列?
- 8. 在R中绘制并保存时间序列列表
- 9. 如何在R中绘制多个序列/时间序列?
- 10. 绘制多个系列在R
- 11. 用flot绘制时间,json系列
- 12. 绘制覆盖时间系列
- 13. 开始时间系列Highcharts在特定日期/时间绘制
- 14. 在R中指定时间系列
- 15. 在R中绘制每日时间序列
- 16. 在R中绘制多变量时间序列的问题
- 17. 在R中绘制时间序列,不能改变y轴
- 18. 在R中绘制顺序(时间序列)数据的子集
- 19. 如何在R中绘制覆盖时间序列?
- 20. 创建增量列绘制R中的时间序列差异
- 21. R系列中的时间序列
- 22. R plotCI mis-asigned colors为系列绘制
- 23. R中的每小时时间系列
- 24. 如何在gnuplot中绘制时间系列?
- 25. 在python中绘制时间序列?
- 26. 在ggplot2中绘制时间序列
- 27. 绘制具有四分位间距的平均和垂直误差线的绘图时间系列,按R列
- 28. 使用ggplot2绘制R中的时间序列,
- 29. 如何绘制R中时间序列的k-medoids结果?
- 30. 如何绘制R中的3D时间序列
是的,我可以用Excel修改它。 –