Hola David, 

Quizás esto te puede ayudar.

He comentado la lineas de los otros métodos de ajuste disponibles en la función 
status_smooth().

library("tidyverse")
pet <-  ggplot(data = cars, aes(x = speed, y = dist)) + 
  geom_point(stat="identity", color = "blue", alpha=0.9) + 
  stat_smooth(method="lm", color = "red")+
  #stat_smooth(method="loess", color = "red")+
  #stat_smooth(method="gam", color = "red")+
  theme_bw()
pet


Las salidas con “loess” y “lm"



Espero ayude 

Saludos

> On 13-05-2022, at 10:34, David Aguinaga <egarens...@gmail.com> wrote:
> 
> Buenos días, 
> 
> Estoy intentando representar una curva suavizada con smooth.spline() usando 
> ggplot2 en lugar de plot, que ofrece un gráfico más simple: 
> 
> attach(cars)
> 
> cars.spline1 <- smooth.spline(speed, dist)
> 
> # gráfico simple
> plot(speed, dist)
> lines(cars.spline1, col="red")
> <image.png>
> # ggplot2
> Quisiera usar ggplot2, pero el resultado que obtengo no es el mismo: 
> 
> pet = ggplot() + geom_point(data = cars, aes(x = speed, y = dist), color = 
> "blue") + geom_line(data = cars, aes(x = speed, y = cars.spline1$data$y, 
> color = "red"))
> > pet
> <image.png>
> 
> _______________________________________________
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es


-- 
C*ertificación ISO 9001/2015*: Sistema de Datos Biológico-Pesqueros (Arica, 
Iquique, Coquimbo, Valparaíso, San Antonio, Talcahuano y Calbuco, 
pesquerías industriales y artesanales)

Attachment: pet
Description: Binary data

Attachment: petlo
Description: Binary data


Espero ayude 

Saludos

On 13-05-2022, at 10:34, David Aguinaga <egarens...@gmail.com> wrote:

Buenos días, 

Estoy intentando representar una curva suavizada con smooth.spline() usando ggplot2 en lugar de plot, que ofrece un gráfico más simple: 

attach(cars)

cars.spline1 <- smooth.spline(speed, dist)

# gráfico simple
plot(speed, dist)
lines(cars.spline1, col="red")
<image.png>
# ggplot2
Quisiera usar ggplot2, pero el resultado que obtengo no es el mismo: 

pet = ggplot() + geom_point(data = "" aes(x = speed, y = dist), color = "blue") + geom_line(data = "" aes(x = speed, y = cars.spline1$data$y, color = "red"))
> pet
<image.png>

_______________________________________________
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

_______________________________________________
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Responder a