Ellipsoids Making Graphs in R

Continuing the discussion from PCoA plots with confidence ellipsoids:

Hello, I've tried to use stat_ellipse () in my R graphs, integrating from QIIME2
(Tutorial: Integrating QIIME2 and R for data visualization and analysis using qiime2R - #21)

Here is my code:
IJ$data$Vectors %>%
dplyr::select(SampleID, PC1, PC2) %>%
left_join(imetadata) %>%
left_join(ishannon) %>%
ggplot(aes(x=PC1, y=PC2, color=Group, shape=Vagotomy, size = shannon_entropy)) +
scale_color_manual(values=c("black","grey50", "steelblue1", "navy")) +
geom_point(alpha=0.85) + #alpha controls transparency and helps when points are overlapping
theme_bw() +
scale_size_continuous(name="Shannon") +

I get the following warning...
"The following aesthetics were dropped during statistical transformation: size
This can happen when ggplot fails to infer the correct grouping structure in the data. Did you forget to specify a group aesthetic or to convert a numerical variable into a factor?"

my size = shannon diversity, which I have when I get from reading in my .qza file of my qiime2 output shannon_vector.qza.

Without stat_ellipse, I get a beautiful graph and the size of all my objects is based on shannon diversity. When I add "stat_ellipse" suddenly black bars appear over my shannon figure legend. This also occurred in an earlier topic, but was not addressed. I've tried size = as.numeric or size = as.factor in the aes code, neither works. Any assistance would be appreciated!

1st screenshot = graph with stat_ellipse() code. The 2nd screenshot is the result when I remove the line stat_ellipse from my R code

Hello Kylynda,

This is an esoteric ggplot issue

This is working as intended. However, that size scale is also being applied to your stat_ellipse() geom object and a matching black bar (of varying size!) is added to the legend.

One option is to turn off legends for this object.


Thank you Colin! Saved me some time trying multiple work-arounds. I ended up making two plots one with ellipsoids and one without so I could get a legend without black bars.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.