我尝试使用ggplot2在同一个地块上绘制多个图层(大约100个)。为此,我创建了一个数据框,其中包含根据' i'
分配的数据rm(list = ls())
# file directory
setwd("E:/stage/Flight_Data/Flight_Data/0200")
library(ggplot2)
# to read txt files
liste_fichier <- list.files("./", pattern=".txt")
n <- length(liste_fichier)
times = list();
altitudes = list();
dataframes = list();
# loop to read the files
for (i in 1:n) {
fichier = liste_fichier[i]
smp <- read.table(fichier, header=FALSE, sep="", skip=3, fill=TRUE)
names(smp) <- c("Date","Time", "Latitude", "Longitude", "Baro.Altitude",
"Radio.Altitude", "Pressure", "A340.static.T", "A340.air.speed",
"A340.ground.speed", "zonal.wind", "meridian.wind", "ozone.vmr",
"H2O.static.T", "relative.humidity", "RH.validity", "RH.accuracy",
"H2O.mmr","CO.vmr", "NOy.vmr", "NO.vmr", "NOx.vmr",
"NOy.uncertainty", "NOy.validity")
smp$ultratime <- strptime(paste(smp$Date, sprintf("%06d",strtoi(smp$Time)), sep=" "),
format="%Y%m%d %H%M%S")
dataframes[[i]] <- data.frame(smp$ultratime,smp$Baro.Altitude)
# Here I want to plot all the files in the same graph, first i want to try only 2
print(ggplot(NULL, aes(x=smp$ultratime, y=smp$Baro.Altitude)) +
geom_line(data=dataframes[[1]])+geom_line(data=dataframes[[2]]))
}
我能够为数据帧[[1]]绘制单个图层,但是当我添加更多图层时,我收到以下错误:
Error in dataframes[[2]] : subscript out of bounds