tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.46k stars 2.02k forks source link

Using categorical fill with many categories in geom_hex results in oversized hexagons #4926

Closed artuurC closed 2 years ago

artuurC commented 2 years ago

Hi,

I am currently trying to add a categorical fill to geom_hex. The problem is that when using too much categories the hexagons get big and obscure the rest of the plot. Attached dataset and reprex should illustrate the problem.

Thanks in advance

image

dataset.csv

test <- as.data.frame(read.csv("./dataset.csv"))
test$colors <- as.factor(test$colors)
ggplot(test) +
  geom_hex(aes(x = dimred_1, y = dimred_2, fill = colors), bins = 200, size = 2) +
  theme_minimal() +
  coord_fixed()

test2 <- test
levels(test2$colors) <- rep(1:15, 2)
ggplot(test2) +
  geom_hex(aes(x = dimred_1, y = dimred_2, fill = colors), bins = 200, size = 2) +
  theme_minimal() +
  coord_fixed()

test3 <- test
levels(test3$colors) <- rep(1:10, 3)
ggplot(test3) +
  geom_hex(aes(x = dimred_1, y = dimred_2, fill = colors), bins = 200, size = 2) +
  theme_minimal() +
  coord_fixed()
yutannihilation commented 2 years ago

Sorry, I cannot reproduce your issue (The data in your CSV doesn't have colors column). This sort of question is a better fit for RStudio Community. Please ask there with a minimal reproducible example (I mean, without the need to download your CSV file). We use this issue tracker for bug reports and feature requests.