Home > Enterprise >  change border thickness of marked ellipses created using ggforce::geom_mark_ellipse()
change border thickness of marked ellipses created using ggforce::geom_mark_ellipse()

Time:10-21

I am trying to change the borders of marked ellipses created using ggforce::geom_mark_ellipse(). How can I remove the borders and just keep the filled ellipses? code for reproducibility is provided below.

enter image description here

library(palmerpenguins)
library(tidyverse)
library(ggplot2)
library(ggforce)

penguins <- penguins %>%
  drop_na()
penguins %>% head() %>% print()


p <- penguins %>%
  ggplot(aes(x = bill_length_mm,
             y = flipper_length_mm)) 
  geom_mark_ellipse(aes(colour=species, fill = species),
                   expand = unit(0.5,"mm"),
                   show.legend = F) 
  geom_point(aes(color = species))

print(p)

CodePudding user response:

You could change the linetype to 0 using ggplot_build like this:

library(ggplot2)
library(ggforce)
library(tidyverse)
library(palmerpenguins)

p <- penguins %>%
  ggplot(aes(x = bill_length_mm,
             y = flipper_length_mm)) 
  geom_mark_ellipse(aes(colour=species, fill = species),
                    expand = unit(0.5,"mm"),
                    show.legend = F) 
  geom_point(aes(color = species))

q <- ggplot_build(p)
q$data[[1]]$linetype <- 0
q <- ggplot_gtable(q)
plot(q)

Created on 2022-10-20 with reprex v2.0.2

CodePudding user response:

You could remove the outline or set the thickness via size, i.e. size=0 or size=NA will work to remove the outline. Another option would be to set the linetype to blank, i.e. lty = "blank".

library(palmerpenguins)
library(tidyverse)
library(ggplot2)
library(ggforce)

penguins <- penguins %>%
  drop_na()

p <- penguins %>%
  ggplot(aes(x = bill_length_mm,
             y = flipper_length_mm)) 
  geom_mark_ellipse(aes(colour=species, fill = species),
                    expand = unit(0.5,"mm"), size = 0,
                    show.legend = F) 
  geom_point(aes(color = species))

print(p)

  • Related