Using facet_wrap to show multiple geom_col charts onto which I superimpose geom_line which are rolling averages done with rollmean. The problem is that rollmean pretty clearly is grabbing values from the preceding facet to calculate the mean. IOW facet 1 looks great. Facet 2 has a line that averages in values from facet 1's data.
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
You're right. This doesn't show the artifact I have in the more complex code I'm actually using. It shows another one: the line should be the 7-day average of the columns, but it clearly isn't.
Here's slightly modified code with better labels. I provided two options for defining df, once is just the last of the four regions shown in the other. Note how in the case of just one region, it seems to be correct, that is, the average line is really the average.
I'm not sure about the original data you posted, but when passed to geom_line as x, the rollmean function is being applied to the entire column "nuovi_positivi" in the order it appears in the original data (there is no grouping). To the best of my knowledge, facetting and grouping in ggplot only provides subsetting of data to plot; it will not group any operations.