Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

natural order of numbers for x not observed #199

Open
smirarab opened this issue Jun 3, 2021 · 0 comments
Open

natural order of numbers for x not observed #199

smirarab opened this issue Jun 3, 2021 · 0 comments

Comments

@smirarab
Copy link

smirarab commented Jun 3, 2021

If the x aesthetic has a natural order (e.g., is simply a number), the data should be sorted by that order before taking the moving average in my opinion. This does not happen. See examples below.

x=(1:10000)*10000
td=data.frame(x=x,y=ifelse(40000000<x & 50000000>x,1,0))

ggplot(aes(x=x,y=y),                
       data=td)+
  geom_point(alpha=0.25,size=0.2)+
  geom_ma(color="red",n = 100,linetype=1,alpha=0.5)

ggplot(aes(x=x,y=y),                
       data=td[order(as.character(x)),])+
  geom_point(alpha=0.25,size=0.2)+
  geom_ma(color="red",n = 100,linetype=1,alpha=0.5)

The only difference between the first figure and the second is the order of lines (in the second one rows are lexicographically ordered instead of numerically). We get a completely wrong picture with the second one. It's computing the moving average for unordered data but it of course will be drawn with correct (numerical) ordering on the x axis. So moving average does not correspond to the x-axis correctly. geom_ma should reorder values based on x before computing averages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant