0

I've been trying to write out an R script that will plot the date-temp series for a set of locations that are identified by a Deployment_ID.

Ideally, each page of the output pdf would have the name of the Deployment_ID (check), a graph with proper axes (check) and correct scaling of the x-axis to best show the date-temp series for that specific Deployment_ID (not check).

At the moment, the script makes a pdf that shows each ID over the full range of the dates in the date column (i.e. 1988-2010), instead of just the relevant dates (i.e. just 2005), which squishes the scatterplot down into uselessness.

I'm pretty sure it's something to do with how you define xlim, but I can't figure out how to have R access the date min and the date max for each factor as it draws the plots.

Script I have so far:

#Get CSV to read data from, change the file path and name
data <- read.csv(file.path("C:\Users\Person\Desktop\", "SampleData.csv"))

#Make Date real date - must be in yyyy/mm/dd format from the csv to do so
data$Date <- as.Date(data$Date)

#Call lattice to library, note to install.packages(lattice) if you don't have it
library(lattice)

#Make the plots with lattice, this takes a while.
dataplot <- xyplot(data$Temp~data$Date|factor(data$Deployment_ID),
   data=data, 
   stack = TRUE, 
   auto.key = list(space = "right"), 
   layout = c(1,1),
   ylim = c(-10,40)
   )

#make the pdf
pdf("Dataplots_SampleData.pdf", onefile = TRUE)

#print to the pdf? Not really sure how this works. Takes a while.
print(dataplot)
dev.off()

1 Answers1

0

Use the scales argument. give this a try

dataplot <- xyplot(data$Temp~data$Date|factor(data$Deployment_ID),
data=data, 
stack = TRUE, 
auto.key = list(space = "right"), 
layout = c(1,1),
scales= list( relation ="free")
  )
eclark
  • 819
  • 7
  • 16
  • I think that just calls the min and max of the whole date set, and what I'm looking for is the min and max for the dates within that particular factor. I'm not sure how to change the min(data$Date) to refer to the particular factor being referenced. Does that make sense? – user3200671 Mar 01 '14 at 02:52
  • That's brilliant! Exactly what I was trying to do! Thank you so much for your help! – user3200671 Mar 01 '14 at 05:06