Dies sind meine Beispieldaten. Ich möchte sowohl y1
als auch y2
gegen x1
in einem einzigen Diagramm plotten. Das ist, was ich tat:Anpassen einer quadratischen Kurve in ggplot
library(ISLR)
library(ggplot2)
y1<-scale(Auto$horsepower,scale = T,center=T)
y2<-scale(Auto$weight,scale = T,center=T)
x1<-Auto$mpg
df<-data.frame(y1,y2,x1)
p<-ggplot(df,aes(x=x1)) +
geom_point(aes(y = y1), shape = 16) +
geom_point(aes(y = y2), shape = 2)
ich eine quadratische Linie sowohl für y1 und y2 gegen x eingefügt werden soll. Ich tat dies:
p + stat_smooth(method = "lm", formula = y ~ x + I(x^2), size = 1)
Es wirft einen Fehler:
Warning message:
Computation failed in `stat_smooth()`:
variable lengths differ (found for 'x')
Andere als diese, wird der stat_smooth Befehl setzen nur eine quadratische Linie, während ich zwei sowohl quadratische Linien müssen für y1
und y2
.
Wie habe ich das in R erreicht?
Dank