我一直试图写出一个R脚本,该脚本将为Deployment_ID标识的一组位置绘制日期-时间序列。
理想情况下,输出pdf的每一页都应具有Deployment_ID的名称(选中),带有正确轴的图形(选中)和x轴的正确缩放比例,以最好地显示该特定Deployment_ID的日期时间序列(不检查)。
[此刻,脚本会创建一个pdf文件,以显示日期列中整个日期范围(即1988-2010年)中的每个ID,而不是仅显示相关日期(即2005年),从而将散点图向下压缩陷入无用。
我很确定这与您定义xlim的方式有关,但是我无法弄清楚R在绘制图时如何让R访问每个因子的日期最小值和日期最大值。
到目前为止我拥有的脚本:
#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()
使用scales参数。尝试一下
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")
)