0
votes

enter image description here

I need plot like this, I have columns of date and time and I can only use basic plotting system of R

I'm trying

GPA = data[, "GPA"]
data[, "Date"] = as.Date(data[,"Date"])
time = paste(data[, "Date"], data[, "Time"])
time = strftime(time, format = "%a %H:%M:%S")
plot(time, GPA)

and it gives me:

Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

1
Can you post some example data?Brian Fisher
Date Time Global_active_power Global_reactive_power Voltage 16/12/2006 17:24:00 4.216 0.418 234.840Bohdan Burlaka

1 Answers

0
votes

The lubridate package is great if you are dealing with time series.
but showing a process just using base R.
Reading the data in as 'dt.raw' it's generally good practice not to use names that mask base functions.

set.seed(1234)  # so you get the same results I do
mydata <- dt.raw[sample(nrow(dt.raw), 10000),]  # only using a subset of your data
colnames(mydata)[3] ="GAP"
mydata$Date = as.Date(mydata$Date, format = "%d/%m/%Y")  # just the date part
mydata$datetime = paste(mydata$Date, mydata$Time)  # concatenating
mydata$datetime = as.POSIXct(mydata$datetime, format = "%Y-%M-%d %H:%M:%S")  # Converting to time format
mydata <- mydata[order(mydata$datetime),] # Sorting by the date time for future line plotting

plot(mydata$datetime, mydata$GAP)

enter image description here