Hi:
Firstly, your example is not completely reproducible because you did
not supply poly.y.values. Tip: It's easier if you create data frames
outside of ggplot2 first rather than try to construct them inline. At
the very least, the code will be better organized. You can shade the
area between the two lines with geom_ribbon(); however, you want to
keep the 'wide form' of ambi.m in order to do that. Removing the
geom_polygon() line in the ggplot call and making a few other changes,
the following appears to work:
ambi.m<-matrix(data=NA,nrow=3,ncol=2)
# You only need the full labels in the legend; see
scale_color_manual() for the change
# Keep variable names simple and avoid spaces, especially if you are
# going to modify with data.frame() or reshape2::melt()
colnames(ambi.m)<-c("Schmitt", "FHiTINGs")
rownames(ambi.m)<-c("Family","Genus","Species")
ambi.m[,1]<-c(2220,2335,2455)
ambi.m[,2]<-c(221,370,639)
# Load the packages
library(reshape2)
library(ggplot2)
# Melt ambi.m into long form
ambi.m.melt<-melt(ambi.m/3317,id.vars=c(rownames(ambi.m),colnames(ambi.m)))
ambi.m.melt<-cbind(ambi.m.melt, num = 1:3)
colnames(ambi.m.melt)[1:2]<-c("Taxon","pipeline")
# Convert ambi.m into a "wide form" data frame, adding a column for num
dflines <- data.frame(num = 1:3, as.data.frame(ambi.m/3317))
# Generate the plot
ggplot() +
geom_line(data = ambi.m.melt, aes(x = num, y = value, color = pipeline),
size = 1) +
geom_ribbon(data = dflines,
aes(x = num, ymax = Schmitt,
ymin = FHiTINGs),
fill = "grey60", alpha = 0.3) +
scale_color_manual(values=c("#C0533A","#92B8B9"),
labels = c("Schmitt et al. Pipeline",
"FHiTINGs Pipeline")) +
scale_x_continuous(breaks = 1:3) +
labs(x = "Taxonomic Level", y = NULL, color = "pipeline") +
theme(panel.background=element_rect(fill="white",color="black"),
axis.text.y=element_blank(),
axis.ticks=element_line(color="gray67"),
panel.grid.major=element_line(color="gray91"),
panel.grid.minor=element_blank())
Some comments re the plot:
(i) I used a darker fill color with alpha transparency in
geom_ribbon() so that the grid lines are a bit more visible - this
should go first because we normally want this as a background layer
rather than a foreground one;
(ii) I used the labels = argument of scale_color_manual() to provide
the full labels for the legend;
(iii) I used labs() to define the titles for each guide;
(iv) I got rid of the label rotation on the x-axis by defining breaks
as integer values in scale_x_continuous().
You probably want to position the polygon layer between geom_ribbon()
and scale_color_manual().
HTH,
Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ggplot2+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.