Вы получаете 4 строки, потому что geom_smooth
наследует shape
и col
aes
от вызова ggplot
, и они неявно определяют group
aes
.
Чтобы избежатьон либо определяет aes
в каждом geom, либо определяет их только в geom_smooth
, отключая наследование:
library(dplyr)
library(ggplot2)
iris %>%
mutate(petalPlus = as.factor(ifelse(Petal.Length > 5.5, 1, 0))) %>%
ggplot() +
geom_point(aes(x = Petal.Length,
y = Petal.Width,
col = Species,
shape = petalPlus)) +
theme_bw() +
geom_smooth(aes(x = Petal.Length, y = Petal.Width), method = "lm")
iris %>%
mutate(petalPlus = as.factor(ifelse(Petal.Length > 5.5, 1, 0))) %>%
ggplot(aes(x = Petal.Length,
y = Petal.Width,
col = Species,
shape = petalPlus)) +
geom_point() +
theme_bw() +
geom_smooth(aes(x = Petal.Length, y = Petal.Width), method = "lm", inherit.aes = FALSE)
Создано в 2018-05-23 с помощью пакета Представить (v0.2.0).