我正在尝试创建这个
但在这样做时,R 会说以下内容:
在 plot.xy(xy, type, ...) 中:强制引入的 NAs`
我将在下面附上我的整个代码:
lnmass <- MoleRat$lnMass
lnenergy <- MoleRat$lnEnergy
caste <- MoleRat$caste
infrequent <- MoleRat[caste == "lazy", ]
frequent <- MoleRat[caste == "worker", ]
lm.infrequent <- lm(lnEnergy ~ lnMass, data = infrequent) #, subset=caste=="lazy")
lm.frequent <- lm(lnEnergy ~ lnMass, data = frequent)
plot(lnmass, lnenergy, pch = as.numeric(caste), col = as.numeric(caste))
abline(lm.infrequent)
abline(lm.frequent)
这是我的数据:
dput(MoleRat)
structure(list(caste = c("worker", "worker", "worker", "worker",
"worker", "worker", "worker", "worker", "worker", "worker", "worker",
"worker", "worker", "worker", "worker", "worker", "worker", "worker",
"worker", "worker", "worker", "lazy", "lazy", "lazy", "lazy",
"lazy", "lazy", "lazy", "lazy", "lazy", "lazy", "lazy", "lazy",
"lazy", "lazy"), lnMass = c(3.850147602, 3.988984047, 4.110873864,
4.17438727, 4.248495242, 4.262679877, 4.343805422, 4.48863637,
4.510859507, 3.951243719, 3.988984047, 4.158883083, 4.234106505,
4.276666119, 4.248495242, 4.465908119, 4.532599493, 4.510859507,
4.828313737, 4.753590191, 4.875197323, 4.382026635, 4.543294782,
4.912654886, 4.700480366, 4.700480366, 4.762173935, 4.859812404,
5.056245805, 5.262690189, 5.147494477, 5.087596335, 4.997212274,
4.875197323, 4.812184355), lnEnergy = c(3.688879454, 3.688879454,
3.688879454, 3.663561646, 3.871201011, 3.850147602, 3.931825633,
3.688879454, 3.951243719, 4.110873864, 4.189654742, 4.143134726,
4.262679877, 4.248495242, 4.510859507, 4.394449155, 4.219507705,
4.48863637, 4.644390899, 5.017279837, 5.043425117, 3.828641396,
4.143134726, 3.555348061, 4.060443011, 4.094344562, 4.304065093,
4.094344562, 4.418840608, 4.234106505, 4.49980967, 4.574710979,
4.532599493, 4.615120517, 4.48863637)), class = "data.frame", row.names = c(NA,
-35L))