0

I want to fill the inside of the dots completely but there are some white spaces inside the dots in a geom_point()

I ran the following code :

library(ggplot2)

set.seed(1)
ggplot(data.frame("Year" = seq(2010, 2019,1), 
                  "Value" = round(rnorm(10), 1), 
                  "Group" = sample(letters[1:3], 10, T)),
       aes(Year, Value)) + 
  geom_point(aes(fill = Group), size = 30, pch = 21)

Which gave me the following plot as output :

enter image description here

As you can see, the color used to fill each plot is not solid and there are white spots inside each dot. What I want is to have dots without those white spots on them.

I also tried with the following code in order to avoid the black line that delimits the dot and see if it fixes the issue but as you can see, the output still has some parts that need to be filled.

set.seed(1)
ggplot(data.frame("Year" = 2013:2022, 
                  "Value" = round(rnorm(10), 1), 
                  "Group" = sample(letters[1:3], 10, T)),
       aes(Year, Value)) + 
  geom_point(aes(color = Group), size = 30)

enter image description here

Is there a way to fix that? I really have a good reason to use points with such sizes.


EDIT:

I added another image (which is a zoom to the original) so you can see the white spaces I'm talking about. They appear even if the border are removed. To remove the border, I used the code suggested by @Caspar V in the comments but it didn't work

enter image description here

bpvalderrama
  • 357
  • 2
  • 8
  • 3
    What OS are you using? What what graphics device are you drawing to? – MrFlick Jun 30 '22 at 16:03
  • 4
    If you switch your plot to ragg graphics, you won't have this problem. – Allan Cameron Jun 30 '22 at 16:09
  • 3
    I can't replicate the problem here (works fine on macOS) but I'm quite sure you can remove the outer border alltogether by setting the stroke to 0: `geom_point(aes(color = Group), stroke = 0, size = 30)` – Caspar V. Jun 30 '22 at 16:24
  • @CasparV. Thank you for the answer but I don't want to delete the border. I want to fill the white spaces inside each of the dots in the plot – bpvalderrama Jun 30 '22 at 18:55
  • @AllanCameron can you please indicate me how to do that? I was taking a look at the documentation of the package but although I could run the examples on it I cannot do it with my own data. – bpvalderrama Jun 30 '22 at 18:57
  • Those white spaces are erroneous "holes" between the border and the fill. Remove the border and you won't see the holes. – Caspar V. Jun 30 '22 at 19:00
  • 1
    @CasparV. I ran the code with the suggestion you made and the holes are still there. I edited the post with a zoom on the image so you can see what I'm talking about – bpvalderrama Jun 30 '22 at 19:07
  • @bpvalderrama are you using Rstudio? – Allan Cameron Jun 30 '22 at 19:25
  • @AllanCameron Yes, I am. I'm also using windows, in case that matters – bpvalderrama Jun 30 '22 at 19:44
  • 2
    In the menu bar of Rstudio, go to Tools - Global Options - General - Graphics, select AGG from the "backend" drop-down. Click on Apply. Restart R, then your graphics display should be fixed. – Allan Cameron Jun 30 '22 at 19:50

0 Answers0