0

I want to get a linegraph in R which has Time along x and temperature along y. Originally I had the data in dd/mm/yyyy hh:mm format, with a time point every 30 minutes. https://www.dropbox.com/s/q35y1rfila0va1h/Data_logger_S65a_Ania.csv

Since I couldn't find a way of reading this into R, I formatted the data to make it into dd/mm/yyyy and added a column 'time' with 1-48 for all the time points for each day

https://www.dropbox.com/s/65ogxzyvuzteqxv/temp.csv

This is what I have so far:

temp<-read.csv("temp.csv",as.is=T)

temp$date<-as.Date(temp$date, format="%d/%m/%Y")  
#inputting date in correct format

plot(temperature ~ date, temp, type="n")
#drawing a blank plot with axes, but without data

lines(temp$date, temp$temperature,type="o") 
#type o is a line overlaid on top of points.

This stacks the points up vertically, which is not what I want, and stacks all the time points (1-48) for each day all together on the same date. Any advice would be much appreciated on how to get this horizontal, and ordered by time as well as date.

Roland
  • 127,288
  • 10
  • 191
  • 288
  • I used your first ".csv", and -I think- it got plotted the way you want: `temp <- read.csv("~/Data_logger_S65a_Ania.csv", stringsAsFactors = F)` ; `temp <- temp[1:4861,]` ; `temp$time <- strptime(temp$Time, "%d/%m/%Y %H:%M")` ; `plot(x = temp$time, y = temp$Celsius..C, type = "l")` – alexis_laz Nov 11 '13 at 10:29
  • Hi Alexis, that is fantastic, thank you. If I would like to add humidity in the same way, and put the scale for that on the right-handside axis, do you know how I could overlay that on the same plot? –  Nov 11 '13 at 11:31
  • A quick way is: `plot(x = temp$time, y = temp$Celsius..C, type = "l", ylim = range(c(temp$Celsius..C, temp$Humidity..rh)), col = rgb(1,0,0,1/3))` ; `lines(x = temp$time, y = temp$Humidity..rh, type = "l", col = rgb(0,0,1,1/3))` ; `axis(4)` ; `mtext("humidity", 4)`. But there exist packages that are concerned with time series and plotting (I'm not familiar with them), that should provide this functionality in a more elegant and precise way. – alexis_laz Nov 11 '13 at 11:50

0 Answers0