I am making a PLS-DA plot in Rstudio, and wanted to show an ellipse around each group.
Previously my code worked fine, but today when I rerun the code, the ellipse around 1 of my groups looks incomplete. Does anyone know why that happened (even though it worked fine previously). I dont get warnings from R.
# legend labels colors
legend_cols <- c("#334B97", "#deb887")
# plot figure
pls.da_plot.M1 <- ggplot(variates, aes(x = x, y = y, fill = group2), color = group2) +
scale_color_manual(values = legend_cols) + # Modify point colour
scale_x_continuous(breaks = c(seq(-30, 60, 30)),
limits = c(-30, 60))+
geom_hline(yintercept = 0,
linetype = "dashed",
linewidth = 0.25,
color = "grey") +
geom_vline(xintercept = 0,
linetype = "dashed",
linewidth = 0.25,
color = "grey") +
geom_point(shape = 21, size = 1.5, stroke = 0.25) +
scale_fill_manual(values = legend_cols) +
stat_ellipse(type = "norm", level = 0.95, geom = "polygon", alpha = 0.2, show.legend = FALSE) +
labs(title = "A. Bacterial meningitis vs. Controls",
y= y.variate, # Adjust title y-axis
x= x.variate) +
theme_classic()+
theme(legend.position = c(1, 1), # Adjust these values as needed
legend.justification = c(1, 1), # Positioning the legend inside the plot
legend.box.just = "right", legend.title = element_blank(), # Remove legend title
legend.spacing.y=unit(0.1, "cm"), # Adjust horizontal spacing between keys and text
legend.spacing.x =unit(0.1, "cm"),
legend.background = element_rect(colour='black', linewidth=0.2),
legend.key = element_rect(fill = NA, color = NA),
legend.margin=margin(c(1,5,5,5))) + #order = top, right, bottom, left
guides(fill = guide_legend(byrow = FALSE))
Nothing in my datasets changed
New contributor
Nora Chekrouni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.