所以我把我的圖設定成:
ten <- c(0. 2,0.16,0. 17,0.188)
fifty <- c(0.1,0. 24,0.17,0.166)
百 <- c(0.3,0. 16,0.16,0.14)
fiveh <- c(0,0。 02,0.04,0.022)
plot(c(10。 10,10, 10。 50,50,, 50,100,100。 100,100。 500,500,500, 500),c(/span>十。 五十,一百,五h),
ylab= "% of Impaired Rivers"。 xlab= "Number of Observations", main= "所有河流的樣本")
我試圖使用abline函式在我的圖表中創建一條趨勢線,但對如何定義我的數值感到困惑。
如果能幫助我了解如何制作一條合適的趨勢線,我將不勝感激。
uj5u.com熱心網友回復:
通過基本的R,(同時,你可以使用rep( . , each = )來說明c(10,10,.....))
df < - c(ten, 五十,一百,五h)
x < - rep(c。 50。 100,500) 。 每個= 4)
plot(x,df ,)
ylab= "% of Impaired Rivers"。 xlab= "Number of Observations"。 main= "所有河流的樣本")
模型<- lm(df ~ x)
abline(model, col = "red")
uj5u.com熱心網友回復:
如果你想嘗試一下tidyverse的方法,下面是方法:
包裝
library(ggplot2)
library(dplyr)
創建一個data.frame
。ten <- c(0. 2,0.16,0. 17,0.188)
fifty <- c(0.1,0. 24,0.17,0.166)
百 <- c(0.3,0. 16,0.16,0.14)
fiveh <- c(0,0。 02,0.04,0.022)
df<-
tibble()
x = c(10。 10, 10。 10, 50, 50,50,50。 100,100。 100,100。 500,500。 500,500),
y = c(十。 五十,一百,五個h)
)。
如何
df %>%
ggplot(aes(x, y))
geom_point() 。
labs()
y = "% of Impaired Rivers",
x = "Number of Observations",
標題 = "所有河流的樣本"
)
geom_smooth(method = "lm"/span>。 se = FALSE)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/306862.html
標籤:
下一篇:<p>我正在使用R編程語言。假設有一家酒店有一個客戶串列,其中有他們的入住和退房時間(注:日期的實際值是"POSIXct",寫成"年月日"。):&l


