2016-12-20 11 views
0

私は雄牛のアロメトリスケーリングを研究している博士課程の学生です。回帰直線と予測勾配線(勾配= 1)を追加するために以下のコードを使用しようとしています。ログに記録されていないデータのログログプロットに、Rはコードを「実行」しますが、適切な行はプロットに表示されません。私はそれがログスケーリングの問題だと思っています。理想的には、従来のログプロット(スケール0.1,1,10,100,1000)のように見えるようにしたいのですが、どのようにRでこれを行うことができます。私が作業しているデータを含めました。あなたが提供できるすべての助けに感謝します!Rログのプロットで曲線をプロットする

stipelengthcm - 1065.0 959.0 925.0 757.0 722.0 663.0 559.0 550.0 550.0 518.0 400.0 379.0 370.0 365.0 363.2 351.8 323.2 306.8 290.0 260.0 251.0 251.0 249.0 242.0 240.0 229.0 220.0 

bulbwidthcm -10.0 16.0 7.8 10.0 10.0 8.5 5.0 6.0 6.0 4.6 4.4 5.6 5.0 7.0 4.2 4.4 5.4 5.4 5.6 6.0 4.0 3.8 4.6 5.0 4.6 5.5 5.4 
library(lmodel2) 
regrlogkelp<-lmodel2(log(stipelengthcm)~log(bulbwidthcm), data=logkelp, nperm=99) 
regrlogkelp 

plot(stipelengthcm, bulbwidthcm, log="xy", xlab = "Stipe Length (cm)", ylab = "Bulb Width (cm)", pch = 1, col = "black") 
curve(exp(regrlogkelp$regression[3,2]) * x^(regrlogkelp$regression[3,3]), add = T) 
var < -(mean(bulbwidthcm)/exp(regrlogkelp$regression[3,2]))^(1/regrlogkelp$regression[3,3]) 
curve((x^2)*(mean(bulbwidthcm)/var^2), add =T, lty = "dashed") 

答えて

1

あなたはRベースのグラフィックスやggplot2でこれを行うことができます。試してみましょうggplot2

データがlogkelpで、回帰がregrlogkelpであるとします。

最初にモデルから予測を行います。

#make predicted values 
logkelp$logcurve1 <- regrlogkelp$regression[3,2] + 
log(bulbwidthcm)*regrlogkelp$regression[3,3] 

ロードggplot2とポイントと予測ラインを求めます。

library(ggplot2) 

ggplot(data=logkelp) + 

#plots the points 
geom_point(aes(x=bulbwidthcm, y=stipelengthcm)) + 

#draws the prediction line; note that y here is exponentiated and matches your expression 
geom_line(aes(x=bulbwidthcm, y=exp(logcurve1))) + 

#put the x axis on the log scale and designate where tick marks will be 
scale_x_log10(breaks=seq(0,20, by=1)) + 

#put the y axis on the log scale and designate where tick marks will be 
scale_y_log10(breaks=seq(0,2000, by=100)) + 

#change from the default ggplot2 style 
theme_bw(base_size = 15) 

enter image description here

あなたが欲しい場合は、軸ラベルや色を変更することができます。信頼帯を使いたい場合はgeom_ribbon()

curve()の結果があなたのポイントのプロットエリアをはるかに上回っていたためにプロットが表示されなかったと思います。 Rはそれを実行していましたが、あなたはそれを見るために縮尺を変えなければなりません。あなたはexp()log()を混ぜています。あなたの回帰とあなたのグラフの間でXとYが入れ替えられたので、混乱します。

Rはcurve()からあなたの結果をプロットしたところこれが実際にある:

plot(stipelengthcm, bulbwidthcm, log="xy", 
xlab = "Stipe Length (cm)", ylab = "Bulb Width (cm)", pch = 1, col = "black", 
ylim=c(1,100000)) 

enter image description here

関連する問題