2014-12-05 31 views
3

我試圖做一個NLS適合與下列數據ggplot: df <- data.frame(t = 0:30, m = c(125.000000, 100.248858, 70.000000, 83.470795, 100.000000, 65.907870, 66.533715, 53.588087, 61.332351, 43.927435, 40.295448, 44.713459, 32.533143, 36.640336, 40.154711, 23.080295, 39.867928, 22.849786, 35.014645, 17.977267, 21.159180, 27.998273, 21.885735, 14.273962, 13.665969, 11.816435, 25.189016, 8.195644, 17.191337, 24.283354, 17.722776)配件與GGPLOT2一個NLS - 類型的錯誤對象「符號」是不是subsettable

我到目前爲止的代碼(有點簡單化)是

ggplot(df, aes(x = t, y = m)) + 
geom_point() + 
geom_smooth(method = "nls", formula=log(y)~x) 

但我得到以下錯誤

Error in cll[[1L]] : object of type 'symbol' is not subsettable 

我瀏覽過計算器,發現類似的問題,但我一直沒能解決問題。我真的很想繪製數據而不改變軸。

任何幫助,非常感謝。

回答

4

對於nls您必須更仔細地指定參數。此外,您可能不想使用log(y),因爲那會繪製對數而不是y。我的猜測是你想使用類似y ~ exp(a + b * x)。見下面的例子。

ggplot(df, aes(x = t, y = m))+ 
    geom_point()+ 
    geom_smooth(method = "nls", formula = y ~ exp(a + b * x), start=list(a=0, b=1), se=FALSE) 

你也可以使用glm,而不是nls。例如,以下給出了相同的解決方案。

ggplot(df, aes(x = t, y = m))+ 
    geom_point()+ 
    geom_smooth(method = "glm", formula = y ~ x, family=gaussian(link = "log"), se=FALSE) 
相關問題