geom_smooth 没有回归线

geom_smooth no regression line

我有以下数据,我正在尝试使用 R 中的 ggplot2 包制作带回归线的散点图

这是我的代码:

df <- read.table(text = "tumor  density fraction
A   2.31    0.224
B   2.76    0.042
C   1.51    0.039
D   1.48    0.429
E   1.97    0.081
F   1.82    0.026
G   1.5 0.083
H   2.38    0.043
I   2.52    0.105
J   1.47    0.200
K   2.17    0.049
L   1.5 0.022
M   2.03    0.100
N   2.2 0.021
O   1.8 0.000
P   1.62    0.055", header = T, sep = "\t")

ggplot(df,aes(x = density, y = fraction, color = tumor))+
  geom_point()+geom_text(label=df$tumor)+
  geom_smooth(method = "lm")

没有绘制回归线?

可能是什么问题?

我们可以从第一个 aes 中删除 color 并在 geom_point

中指定它
ggplot(df,aes(x = density, y = fraction))+
   geom_point(aes(color = tumor))+
   geom_smooth(method = 'lm')+ 
   geom_text(label=df$tumor)

-输出

数据

df <- structure(list(tumor = c("A", "B", "C", "D", "E", "F", "G", "H", 
"I", "J", "K", "L", "M", "N", "O", "P"), density = c(2.31, 2.76, 
1.51, 1.48, 1.97, 1.82, 1.5, 2.38, 2.52, 1.47, 2.17, 1.5, 2.03, 
2.2, 1.8, 1.62), fraction = c(0.224, 0.042, 0.039, 0.429, 0.081, 
0.026, 0.083, 0.043, 0.105, 0.2, 0.049, 0.022, 0.1, 0.021, 0, 
0.055)), class = "data.frame", row.names = c(NA, -16L))