R 当我使用stat_smooth时,趋势线不会显示在图中

R 当我使用stat_smooth时,趋势线不会显示在图中,r,R,我有一个数据有6列,分别命名为:DBF、BF、MM、TC、TA和DL。我用它们作为变量。并使用名为hardwood.content的列作为自变量。我在r中使用了以下代码 printf("%d\n", 42) library(ggplot2) library(reshape2) nrn <- melt(nrn, inrn.vars="hardwood.content") ggplot(nrn, aes(hardwood.content,value)) + geom_point() +

我有一个数据有6列,分别命名为:DBF、BF、MM、TC、TA和DL。我用它们作为变量。并使用名为hardwood.content的列作为自变量。我在r中使用了以下代码

printf("%d\n", 42)
library(ggplot2)
library(reshape2)
nrn <- melt(nrn, inrn.vars="hardwood.content") 
ggplot(nrn, aes(hardwood.content,value)) + 
geom_point() + 
stat_smooth(method = "lm", se=FALSE,colour='black')+
facet_wrap(~variable)+
xlab("Hardwood content (%)")+ylab("Number of regeneration per ha")

这一定与您的数据集有关。如果将数据集替换为内置的
iris
数据集(即将nrn替换为iris等),则绘图代码工作正常。编辑您的问题以包含您的数据(或部分数据)怎么样?@Ben,我不知道如何加载我的数据。我试着复制它们,但看起来很乱。你知道如何处理吗?只需使用命令
dput(你的数据集)
即可使
lm
正常工作,
hardwood。内容应为数字。是这样吗?@Erwan LE PENNEC,当我使用as.numeric(hardwood.content)时。值“0-25、40-65、75-100”变为“1、2、3”。我怎样才能解决这个问题?
hardwood    DBF      BF         MM       TC      TA     DL
0-25        15250    41206.8    5000     0       5000   0
0-25        8846.1   40517.2    0        0       0      0
0-25        10833.3  30967.7    20833.3  0       0      0
40-65       8750     14250      7884.6   42500   0      7727.2
40-65       0        20217.3    13043.4  0       0      8571.4
40-65       7500     12948.7    15000    25833.3 5000   8750
75-95       0        10000      13225.8  7500    5000   0
75-95       0        5000       10517.2  53461.5 5000   33095.2
75-95       5000     8666.6     7600     20000   5000   18965.5