hrbrmstr / ggalt

:earth_americas: Extra Coordinate Systems, Geoms, Statistical Transformations & Scales for 'ggplot2'
https://cran.r-project.org/web/packages/ggalt/vignettes/ggalt_examples.html
Other
654 stars 99 forks source link

geom_xspline only works on properly arranged data frames #72

Open tjebo opened 3 years ago

tjebo commented 3 years ago

This behaviour is not really clear from the documentation. It would help to have this information added. (or change the underlying Stat to first arrange by x value.)

Example (partly taken from the documentation example:

library(ggplot2)
library(ggalt)

set.seed(1492)
dat <- data.frame(x=c(1:10, 1:10, 1:10),
                  y=c(sample(15:30, 10), 2*sample(15:30, 10),
                      3*sample(15:30, 10)),
                  group=factor(c(rep(1, 10), rep(2, 10), rep(3, 10)))
)

newdat <- dat[1:10,]

ggplot(newdat, aes(x, y)) +
  geom_point(color="black") +
  geom_xspline(size=0.5)


weirddat <- newdat[sample(nrow(newdat)), ]

ggplot(weirddat, aes(x, y)) +
  geom_point(color="black") +
  geom_xspline(size=0.5)

Created on 2021-01-01 by the reprex package (v0.3.0)