I've got some data I used to plot a few months ago in ggplot with no problems but now it produces very strange output. The data is structured like below:
factor time.step run.number total.tigers
0.25 0 1 128
0.25 1 1 129
0.25 2 1 134
...
0.25 0 32 122
0.25 1 32 142
0.25 2 32 153
...
1 0 32 152
1 1 32 137
1 2 32 158
In other words, I have output total.tigers
from models run at different factor
levels (i.e., 0.25., 0.5, 0.75, 1). They were run for 240 time.steps
and replicated 32 times (i.e., run.number
). I'm interesting in plotting total.tigers
over time.step
, with total.tigers
summarized (mean and confidence intervals) over all 32 run.number
for each factor
level.
My code looks like:
stat_sum_df <- function(fun, geom="crossbar", ...) {
stat_summary(fun.data=fun, geom=geom, ...)
}
ggplot(data=finaldata.sub,
aes(x=time.step, y=total.tigers, color=factor, group=factor)) +
stat_sum_df("mean_cl_normal", geom = "smooth", size = 1) + xlab("Month") + ylab("Individuals") +
scale_x_continuous(breaks = seq(0, 240, by=24))
However, instead of getting lines showing changes in total.tigers
sequentially over time, I'm getting outputs that zig-zag across time.steps
. See picture here.
Any suggestions on resolving this?