[R-es] ggplot2 vs plot
David Aguinaga
eg@ren@e21 @end|ng |rom gm@||@com
Vie Mayo 13 16:34:31 CEST 2022
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: 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: image.png]
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20220513/58025315/attachment-0001.html>
------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 8359 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20220513/58025315/attachment-0002.png>
------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 10922 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20220513/58025315/attachment-0003.png>
Más información sobre la lista de distribución R-help-es