Что-то, как это будет делать:
# 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)
Да, я могу изменить его Excel. –