I am trying to plot a line graph for temperature time-series. Instead of making an exact line it shows variations at each point.
I have written this code for this line graph
temp<-read.csv("E:/Salford Work/Data Mining/Data/Tensor houses/8 John boste court/temReadings (5).csv");
rdate <- as.Date(temp$Date.Time, "%d/%m/%Y %H:%M");
plot(temp$Reading~rdate, type="l", col="blue", axes=F);
axis(1,rdate,format(rdate,"%d-%m-%y"));
read<-temp[,4];
axis(2,read);
Can anyone please help me to draw a simple line.
This usually results from having an x-axis variable that is categorical. I'm not sure if this is the case for you since you seem to have converted to
as.Date
. Nevertheless, I would avoid the formula (~
) notation when not calling a dataframe in your plot function:Either way, make sure that
class(rdate)
returns"Date"
.Edit:
The problem is that the hours, minutes, and seconds are getting removed from your data when using
as.Date
, and most of your dates are on the same day - Thus you lose resolution. Instead, you should use "POSIXlt" or "POSIXct" format and use thestrptime
function for the conversion: