2017-06-23 37 views
0

Dears,我有空氣溫度數據,我需要用不平滑的曲線繪製三個選定年份的正態分佈。我正在尋找的圖與圖2的here類似,其中我可以看到每條曲線(即噪音)的溫度波動。繪製不明朗的正態分佈r

這裏是一個在線的數據和代碼示例:

Cowtan<-read.table("http://www-users.york.ac.uk/~kdc3/papers/coverage2013/had4_krig_v2_0_0.txt", header=F) 
names(Cowtan)<-c("Year", "Temperature", "Uncertainty1", "Uncertainty2", "Uncertainty3") #Name the columns 

S1850s<-subset(Cowtan, Year<1860) #Get subsets of each decade 
S1950s<-subset(Cowtan, Year>=1950 & Year<1960) 
S2007<-subset(Cowtan, Year>=2007 & Year<2017) 
D1850s=density(S1850s$Temperature) #Get the density kernals 
D1950s<-density(S1950s$Temperature) 
D2007<-density(S2007$Temperature) 
plot(D1850s, main="Bell curve of temperatures during selected decades", xlab="Temperature anomalies (ºC)",xlim=c(-1.1,1.3), ylim=c(0,3), lwd=1.5) 
points(D2007, type="l",col="red", lwd=1.5) 
points(D1950s, type="l",col="blue", lwd=1.5) 
legend("topleft", legend=c("1850s", "1950s", "2007-2016"), col=c("black", "blue", "red"), lwd=2) 
+0

什麼是「不平滑的正態分佈」? – Roland

回答

1

如何只產生一個正態分佈的點,並將它們添加到情節?

Cowtan<-read.table("http://www-users.york.ac.uk/~kdc3/papers/coverage2013/had4_krig_v2_0_0.txt", header=F) 
names(Cowtan)<-c("Year", "Temperature", "Uncertainty1", "Uncertainty2", "Uncertainty3") #Name the columns 

S1850s<-subset(Cowtan, Year<1860) #Get subsets of each decade 
S1950s<-subset(Cowtan, Year>=1950 & Year<1960) 
S2007<-subset(Cowtan, Year>=2007 & Year<2017) 
D1850s=density(S1850s$Temperature) #Get the density kernals 
D1950s<-density(S1950s$Temperature) 
D2007<-density(S2007$Temperature) 
plot(D1850s, main="Bell curve of temperatures during selected decades", xlab="Temperature anomalies (ºC)",xlim=c(-1.1,1.3), ylim=c(0,3), lwd=1.5) 
points(D2007, type="l",col="red", lwd=1.5) 
points(D1950s, type="l",col="blue", lwd=1.5) 

norm.dist <- rnorm(1000000, 0, 0.3) 
points(density(norm.dist), type = "l", col="green") 


legend("topleft", legend=c("1850s", "1950s", "2007-2016", "norm dist"), col=c("black", "blue", "red", "green"), lwd=2) 
+0

謝謝,但我不是在尋找這個。 – Moore

+0

你能解釋我的解決方案有什麼問題嗎? – MikolajM

1

這裏是在圖2

set.seed(1) 
x <- rnorm(10000) 
plot(density(x, bw=0.01)) 

enter image description here

所示。如可以看到的「不平滑的曲線」類似的一個實例,我平滑帶寬bw設置爲一個非常小的值,以致密度圖似乎「不平滑」。該圖中的關鍵點在於大量觀測的可用性。使用你的數據 最後的情節是這樣的:

enter image description here

我希望這可以幫助你。

P.S.在上圖中,我使用density函數中的kernel="epanechnikov"選項。