2013-06-01 114 views
2

我適合兩種模型的500條曲線。我根據模型繪製每個擬合以檢查相似之處。麻煩在於一套線將覆蓋另一套。在下面的例子中,物流線完全由樣條線覆蓋。ggplot2中的重疊線

有沒有一種方法可以繪製兩個適合並防止重疊,所以我仍然可以看到兩組線條?也許通過改變顏色或使用不同的幾何?

ggplot(data=fullData,aes(X,Y,color=Model,group=id))+geom_line() 

enter image description here

> dput(head(fullData)) 
structure(list(X = c(-6, -5.97595190380762, -5.95190380761523, 
-5.92785571142285, -5.90380761523046, -5.87975951903808), Model = c("Logistic", 
"Logistic", "Logistic", "Logistic", "Logistic", "Logistic"), 
    Y = c(40.2327812336246, 40.2062250618146, 40.1837765087578, 
    40.1613100197852, 40.1387156930829, 40.1159930605682), id = c(1L, 
    1L, 1L, 1L, 1L, 1L)), .Names = c("X", "Model", "Y", "id"), row.names = c(NA, 
6L), class = "data.frame") 
+5

我可能只是調整阿爾法。如果您發佈數據的dput()(或至少幾行),那麼人們可以發佈一些示例。 – David

+0

@David將alpha調整到一個小的級別(.1)會有幫助,謝謝。我不知道如何發佈數據,因爲一個適合在500點的網格... – Glen

+0

@Glen:閱讀http://tinyurl.com/reproducible-000關於創建可重複的例子的提示... –

回答

3

高興阿爾法摸索出適合你。如果你想成爲能夠接受+關閉,你可以直接點擊加入阿爾法這個例子的要求(有一些模擬數據):

library(ggplot2) 

#function to generate some data 
makeLine <- function(x){ 
    set.seed(x) 
    Y <- c(runif(1,38,42),runif(1,34,38),runif(1,28,32),runif(1,23,27),runif(1,10,20)) 
    X <- c(-6,-3,0,3,6) 
    if(x > 40){ 
    model <- "Spline" 
    } else { 
    model <- "Logistic" 
    } 
    data.frame(X=X,Y=Y,id=x,model=model) 
} 

#make a data set 
dat <- do.call(rbind,lapply(1:100,makeLine)) 

#add alpha to your plot 
ggplot(data=dat,aes(X,Y,color=model,group=id)) + geom_line(alpha=0.15) 

enter image description here