Hi again...
here is an update of my progress:
I used Joran's approach of interpolating (see below).
The plot is now working after some adaptations to my data structure.
There is still a little question concerning the plot (transparency) itself (see at the end).
1) My data frame included also some grouping variables
for facet-plotting. So, first I had to run the interpolation and
creation of the new data frame for upper and lower in
a loop.
2) As my original x data were highly skewed (lot of very small values, fewer
large values) the interpolation failed at the parts of very small values. Thus I used exp(log) in combination with seq to get a log-scaled sequence
for the new x values (and I increased the amount of points)
Here the example of the loop (over species and steps) and the log-scaled sequence:
# Get upper and lower for geom_ribbon
ls = list()
for(j in levels(df$species)){
for(i in levels(df$step)){
df1 <- df[(df$species==j & df$step==i & df$ci!="fit"),]
r <- range(df1$value)
xout <- exp(seq(log(r[1]), log(r[2]), length.out=100))
lower <- with(df1,approx(value[ci=="lwr"],y=abscount[ci=="lwr"],xout=xout,rule=2))$y
upper <- with(df1,approx(value[ci=="upr"],y=abscount[ci=="upr"],xout=xout,rule=2))$y
df2 <- data.frame(x=xout,lower=lower,upper=upper,species=j,step=i)
ls[[paste("ci.df2",j,i,sep="_")]] <- df2
}}
df3 <- as.data.frame(do.call(rbind, ls))
The resulting dataframe I then used in the ggplot command with facets (grouping variable = steps, facetting = species).
There is just one little question concerning the plot itself and the
transparency. When I use the ggplot-command as mentioned by Joran:
ggplot(df) +
geom_ribbon(data = df1,aes(x = xout,ymin = lower,ymax = upper),alpha = 0.5)
+ geom_line(aes(x=x,y=y,group = var))
...also the line is plotted with the transparency level alpha=0.5. How do
I change that, so that the ribbon is transparent but not the line which plots on top of the ribbon?
Best regards,
Johannes
-------- Original-Nachricht --------
> Datum: Mon, 7 May 2012 08:04:02 -0700 (PDT)
> Von: Joran <
joran...@gmail.com>
> An:
ggp...@googlegroups.com
> Betreff: Re: Plot band of uncertainty