stackinator
stackinator

Reputation: 5819

ggplot2 geom_hex white border

If you look at the screen grab below you'll see that five rows of my geom_hex have a white border that make the plot look goofy. Why is this? How do I stop it? When I save with ggsave the problem gets worse (more white lines)!

library(tidyverse) 
ggplot(diamonds, aes(carat, price)) + geom_hex(bins = 50)
ggsave("geom_hex.png")

Picture1.png

Upvotes: 2

Views: 955

Answers (1)

mdag02
mdag02

Reputation: 1175

By default geom_hex only fills the hexagons and not their contours. Add a contour line (a "colour" in ggplot-speak) coloured with the same colour scale and that will fill the voids :

library(tidyverse) 
ggplot(diamonds, aes(carat, price)) +
  geom_hex(aes(colour = ..count..), bins = 50)

plot

Upvotes: 6

Related Questions