friendly / ggbiplot

A ggplot2 based biplot for principal components-like methods
https://friendly.github.io/ggbiplot/
11 stars 0 forks source link

Fill isn't working for ellipses using geom_polygon() #1

Closed friendly closed 1 year ago

friendly commented 1 year ago

In ggbiplot.r around lines 261-268 I replaced code using geom_path() with geom_polygon() so that the ellipses for the groups could be filled. Yet, in testing, this has no effect (ellipses are unfilled). What is wrong here?

I want to make this optional, so I'd add an argument, ellipse.fill = T / F / alpha, but I have to get this working first.

 g <- g + geom_polygon(data = ell, 
                          aes(color = groups, 
                              fill = groups
                              ),
                          alpha = 0.4,    # MF: why doesn't this have any effect?
                          linewidth = ellipse.linewidth)

Code to test any changes in your local copy of this repo:

source("ggbiplot.r")
data(wine, package="ggbiplot")
wine.pca <- prcomp(wine, scale. = TRUE)
ggbiplot(wine.pca, groups=wine.class,
         ellipse = TRUE, 
         ellipse.linewidth = 1.2,
         circle = TRUE,
         varname.color = "darkred",
         varname.size = 4) +
  theme_minimal() +
  theme(legend.direction = 'horizontal', legend.position = 'top')
friendly commented 1 year ago

This was posted to SO, https://stackoverflow.com/questions/77113516/ggplot2-fill-isnt-working-for-ellipses-using-geom-polygon/ The answer was faulty calculation of the ellipses, now fixed