there are no secondary points in the ggplot

Try this for non filled points:

library(tidyverse)
#Code
dat %>% group_by(groups) %>% ggplot() +
  aes(x, y, color = groups, shape = groups)+
  geom_point(size = 2) + theme_classic()+ 
  stat_ellipse(level = .6) +
  geom_point(data = dat2, 
             mapping = aes(x = mean_x, y = mean_y,fill = factor(groups)), 
             size = 4, show.legend = F,shape=21) +
  geom_smooth(data = dat2, mapping = aes(x = mean_x, y = mean_y), 
              method = "lm", se=F, color = 1, formula = 'y ~ x')  ## geom_smooth doesn't show

Output:

enter image description here

For smooth try this:

#Code 2
dat %>% group_by(groups) %>% ggplot() +
  aes(x, y, color = groups, shape = groups)+
  geom_point(size = 2) + theme_classic()+ 
  stat_ellipse(level = .6) +
  geom_point(data = dat2, 
             mapping = aes(x = mean_x, y = mean_y,fill = factor(groups)),
             size = 4, show.legend = F,shape=21) +
  geom_smooth(data = dat2, mapping = aes(x = mean_x, y = mean_y,group=1), 
              method = "lm", se=F, color = 1, formula = 'y ~ x')+
  scale_fill_manual(values=rep('black',3))

Output:

enter image description here

Try this for keeping same shape:

#Code 3
dat %>% group_by(groups) %>% ggplot() +
  aes(x, y, color = groups, shape = groups)+
  geom_point(size = 2) + theme_classic()+ 
  stat_ellipse(level = .6) +
  geom_point(data = dat2, 
             mapping = aes(x = mean_x, y = mean_y,color = factor(groups)),
             size = 4, show.legend = F,color='black') +
  geom_smooth(data = dat2, mapping = aes(x = mean_x, y = mean_y,group=1), 
              method = "lm", se=F, color = 1, formula = 'y ~ x')+
  scale_fill_manual(values=rep('black',3))

Output:

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top