简体   繁体   English

R 日期格式 - 软件

[英]R date format - Software

Good morning everyone,大家,早安,

I want to represent a graph with dates on the x-axis and prices on the y-axis.我想用 x 轴上的日期和 y 轴上的价格来表示一个图表。 When I import the CSV document, I have no problem.当我导入 CSV 文档时,我没有问题。 Each type of information is in its column, and the dates are in a suitable format.每种类型的信息都在其列中,日期采用合适的格式。 But when I try to graph this data.但是当我尝试绘制这些数据时。 I get non-conforming lines, and the date format is not the same (now: 0002, 0004, 0006, 0008, 0010, etc...).我得到了不合格的行,并且日期格式不一样(现在:0002、0004、0006、0008、0010 等...)。 What can I do?我能做什么? I thank you in advance.我提前谢谢你。

Here is my code and the pictures:这是我的代码和图片:

#Put the data in a matrix p
p <-read.csv("JSE_Price_index_and_Total_Returns1.csv", header = TRUE , sep = ",")

names(p)
names(p)<-c("Date","Price Index","Total Return Index")

#Adjust maybe date format - i don't knowv

????

#Representer Price Index - plot:
plot(as.Date(p$Date),p$Price Index, type = "l", col="black", lwd = 1)

在此处输入图片说明

在此处输入图片说明

Try this code:试试这个代码:

p$Date <- as.Date(p$Date, "%m/%d/%Y")
 plot(`Price Index` ~ Date, p, xaxt = "n", type="l")
 axis(1, p$Date, format(p$Date, "%b %d"), cex.axis = .7)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM