brrav0 / RTEAnalytics

0 stars 3 forks source link

How to plot data by date #15

Open GaojunShen opened 8 years ago

GaojunShen commented 8 years ago

I am trying to plot a graph by this this command:

supply_data = DataSet$Consumption
plot(factor(DataSet$Date), supply_data)

but everytime I got the graph with date not in order, would you please help me handle this? @gillesalex07 @brrav0 @Sefimenko

rplot

tevgeniou commented 8 years ago

which file(s)?

tevgeniou commented 8 years ago

as.Date(DataSet$Date, format("%m/%d/%Y"))[1] [1] "2012-01-01" plot(as.Date(DataSet$Date, format("%m/%d/%Y")))

screen shot 2016-02-04 at 15 52 02

GaojunShen commented 8 years ago

This one : https://github.com/GaojunShen/RTEAnalytics/blob/master/RTEAnalytics-Gaojun-01.Rmd @tevgeniou

GaojunShen commented 8 years ago

My problem is when I used 'as.Date', the x axis is number of days not the exact date after plot. How to solve that?

tevgeniou commented 8 years ago

not sure what you want to do, but try this. maybe something like this?

x = as.Date(DataSet$Date, format("%m/%d/%Y")) plot(x, axes=FALSE, type = "l", ylab = "y axis label bla", xlab="x axis label bla",main="main label bla", lwd=1.4) axis(1,at=seq(1,length(x),length.out=10),labels=DataSet$Date[seq(1,length(x),length.out=10)],cex.axis=0.8,las=3) axis(2,cex.axis=1.1)

play around with length.out, too.

GaojunShen commented 8 years ago

In the first chart, the graph is ok but when I look at the x-axis, the date is not from 2012-2013-2014 but 2012-2012-2014....and it plots 2013 in the end which is weird. I got the same problem for lines 27-32 which the x-axis is disordered like this

rplot01

tevgeniou commented 8 years ago

it prints the labels at "positions" at=seq(1,length(x),length.out=10),labels=DataSet$Date[seq(1,length(x),length.out=10)]

of course you can manually ask it to print the labels at whatever positions you like, but if your data has, for example, 200 datapoint for 2012 and 5 points for 2013 clearly 2012 should appear more often if you "equally-space" the x-axis labels.

try also to see what this does: seq(1,100,5) etc (help(seq))