2014-02-27 37 views
0

我有如下情節數據

Location Date   x1.1DCE C12DCE Ethane Ethylene PCE   12DCE TCE VC 
"IN-1B1" 2013-01-29 5.00 98.000 0.050 0.900 4.10e+02 5.000 12.000 5.00 
"IN-1B1" 2013-06-27 0.50 385.000 10.000 10.500 2.80e+02 1.000 24.500 19.50 
"IN-1B1" 2013-10-24 0.50 74.000 5.000 11.500 2.65e+02 1.000 22.500 7.45 
"IN-1B2" 2007-08-28 0.25 0.280 NA NA 1.50e+02 0.250 1.900 0.25 
"IN-1B2" 2007-10-31 0.50 0.310 NA NA 2.10e+02 0.500 4.500 0.50 
"IN-1B2" 2008-04-02 4.15 4.150 NA NA 1.30e+02 4.150 1.800 4.15 
"IN-1B3" 2007-10-31 0.25 0.300 NA NA 1.90e+02 0.250 1.700 0.25 
"IN-1B3" 2009-05-06 0.25 0.170 NA NA 2.00e+02 0.250 1.500 0.25 

在第1列的位置標識符標識,其中樣品收集隨時間的位置被組織的數據幀。有20個地點,每個地點都有不同時間收集的樣本結果。我想創建結果的散點圖矩陣(按列)與時間的關係,並使用位置標識符來劃分要包含在每個散點圖中的數據。任何幫助或引用將不勝感激。由於

+0

你的意思['facet_grid'(http://docs.ggplot2.org/0.9。 3.1/facet_grid.html)? – krlmlr

+0

「結果」與時間的含義是什麼?什麼將在y軸上?哪列? –

+0

歡迎來到SO。請提交一份完全可重複的(並且最好是最少的)示例,因爲它使得幫助變得更容易。 – geotheory

回答

0

我想你可能會找這樣的:

# creating initial dataframe 
df <- read.table(text = " 
Location Date   x1.1DCE C12DCE Ethane Ethylene PCE   12DCE TCE VC 
IN-1B1 2013-01-29 5.00 98.000 0.050 0.900 4.10e+02 5.000 12.000 5.00 
IN-1B1 2013-06-27 0.50 385.000 10.000 10.500 2.80e+02 1.000 24.500 19.50 
IN-1B1 2013-10-24 0.50 74.000 5.000 11.500 2.65e+02 1.000 22.500 7.45 
IN-1B2 2007-08-28 0.25 0.280 NA NA 1.50e+02 0.250 1.900 0.25 
IN-1B2 2007-10-31 0.50 0.310 NA NA 2.10e+02 0.500 4.500 0.50 
IN-1B2 2008-04-02 4.15 4.150 NA NA 1.30e+02 4.150 1.800 4.15 
IN-1B3 2007-10-31 0.25 0.300 NA NA 1.90e+02 0.250 1.700 0.25 
IN-1B3 2009-05-06 0.25 0.170 NA NA 2.00e+02 0.250 1.500 0.25", header = TRUE, strip.white = TRUE) 

# converting dataframe into long format 
require(reshape2) 
df2 <- melt(df, id=c("Location","Date")) 

# creating a facetted plot 
require(ggplot2) 
ggplot(df2, aes(x=as.Date(Date), y=value, color=variable)) + 
    geom_point() + 
    facet_grid(. ~ Location) 

結果: enter image description here