Closed marwa38 closed 2 years ago
Hi @marwa38
I think it is working perfectly. If you observe closely, you will notice the spacing in both axes when using stat_ellipse
and coord_equal
are the same. I think the different breaks in the X- and Y-axis is making it hard to notice this.
For example:
library(phyloseq)
library(ggplot2)
data(enterotype)
ps <- enterotype
bray.pcoa <- ordinate(ps, method = "PCoA", distance = "bray")
p1 <- plot_ordination(ps, bray.pcoa, color = "Enterotype", axes = c(1,2)) +
geom_point(size = 1) +
labs(title = "Original")
p2 <- plot_ordination(ps, bray.pcoa, color = "Enterotype", axes = c(1,2)) +
geom_point(size = 1) + coord_equal() +
labs(title = "coord_equal")
p3 <- plot_ordination(ps, bray.pcoa, color = "Enterotype", axes = c(1,2)) +
geom_point(size = 1) + stat_ellipse() +
labs(title = "stat_ellipse")
p4 <- plot_ordination(ps, bray.pcoa, color = "Enterotype", axes = c(1,2)) +
geom_point(size = 1) + coord_equal() + stat_ellipse() +
labs(title = "coord_equal + stat_ellipse")
gridExtra::grid.arrange(p1, p2, p3, p4)
If we set the same breaks
settings for X- and Y-axis
p1 <- plot_ordination(ps, bray.pcoa, color = "Enterotype", axes = c(1,2)) +
geom_point(size = 1) +
scale_x_continuous(breaks = seq(-1,1,0.2)) + scale_y_continuous(seq(-1,1,0.2)) +
labs(title = "Original")
p2 <- plot_ordination(ps, bray.pcoa, color = "Enterotype", axes = c(1,2)) +
geom_point(size = 1) + coord_equal() +
scale_x_continuous(breaks = seq(-1,1,0.2)) + scale_y_continuous(seq(-1,1,0.2)) +
labs(title = "coord_equal")
p3 <- plot_ordination(ps, bray.pcoa, color = "Enterotype", axes = c(1,2)) +
geom_point(size = 1) + stat_ellipse() +
scale_x_continuous(breaks = seq(-1,1,0.2)) + scale_y_continuous(seq(-1,1,0.2)) +
labs(title = "stat_ellipse")
p4 <- plot_ordination(ps, bray.pcoa, color = "Enterotype", axes = c(1,2)) +
geom_point(size = 1) + coord_equal() + stat_ellipse() +
scale_x_continuous(breaks = seq(-1,1,0.2)) + scale_y_continuous(seq(-1,1,0.2)) +
labs(title = "coord_equal + stat_ellipse")
gridExtra::grid.arrange(p1, p2, p3, p4)
As for the warning message with cov.trob
. It's to do with how the ellipse was calculated when using stat_ellipse
, the default is using multivariate t-distribution and that uses the cov.trob
function from the MASS
package. Although you can change the tol
setting in cov.trob
to adjust for the convergence tolerance for fitting, the stat_ellipse
doesn't allow you to adjust this. If you want to explore more about this, you can approach the ggplot2
's developers.
many thanks @ycl6, this is so helpful and insightful :)
hello .. I am not sure if these are bugs? please let me know
without coord_equal() and without stat_ellipse()
with coord_equal()
with using coord_equal() and stat_ellipse() with using stat_ellipse()
Could you please advise why I am not getting the correct aspect ratio of the plot? even after using coord_equal() ? and why I am getting this warning message when tried using stat_ellipse()?
let me know if you would like to have a look into ps.3.rare many thanks