Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2: geom_polygon with no fill

Tags:

I hope, you dont need data for this problem, because I believe I am just making a stupid syntax error. The following code:

ggplot()+   geom_point(data=sites, aes(x=NMDS1, y=NMDS2, shape=group), colour="grey") +     geom_point(data=species, aes(x=NMDS1, y=NMDS2, color=phyla), size=3, shape=20) + scale_colour_manual(values=Pal1) +   geom_segment(data = BiPlotscores, aes(x = 0, xend = NMDS1, y= 0, yend = NMDS2),                arrow = arrow(length = unit(0.25, "cm")), colour = "black") +   geom_text(data = BiPlotscores, aes(x = 1.1*NMDS1, y = 1.1*NMDS2, label = Parameters), size = 3) + coord_fixed()+   theme(panel.background = element_blank()) +   geom_polygon(data = hulls, aes(x=NMDS1, y=NMDS2, colour=phyla, alpha = 0.2)) 

leads to the following result:

enter image description here

(This is not the final product :)). I would like to have the polygons unfilled, or very just neatly filled. I do not want them to be greyish, for sure. Fill doesnt do anything, and apparently fiddling with alpha doesnt change anything, either.

Any ideas are superwelcome. Thank you very much!

"Hulls" is coming from the following code (as found here somewhere):

#find hulls library(plyr) find_hull <- function(df) df[chull(df$NMDS1, df$NMDS2), ] hulls <- ddply(species , "phyla", find_hull) 
like image 336
nouse Avatar asked Aug 22 '14 14:08

nouse


People also ask

How do I create a transparent fill in ggplot2?

You can optionally make the colour transparent by using the form "#RRGGBBAA" . An NA , for a completely transparent colour.

What does Alpha do in R?

Alpha refers to the opacity of a geom. Values of alpha range from 0 to 1, with lower values corresponding to more transparent colors.

What is Geom_polygon in R?

Source: R/geom-polygon.r. geom_polygon.Rd. Polygons are very similar to paths (as drawn by geom_path() ) except that the start and end points are connected and the inside is coloured by fill . The group aesthetic determines which cases are connected together into a polygon.


1 Answers

If you want transparent fill, do fill=NA outside the aes()-specification.

library(ggplot2) data <- data.frame(y=c(2,2,1), x=c(1,2,1)) ggplot(data) + geom_polygon(aes(x=x, y=y), colour="black", fill=NA) 
like image 193
fabians Avatar answered Oct 09 '22 03:10

fabians