erocoar / gghalves

✂️ Easy half-half geoms in ggplot2
https://erocoar.github.io/gghalves/
Other
241 stars 13 forks source link

color by for one half only #15

Open ScaonE opened 3 years ago

ScaonE commented 3 years ago

Dear all,

I'd like to be able to specify a color only for the 2nd half of the plot. See "reprex" below :

# Not specifying a color, all goes well
ggplot(
  ToothGrowth %>%
    mutate(across(dose, as.character)),
  aes(x = dose, y = len)
) + 
  geom_half_boxplot() +
  geom_half_point() +
  theme_bw()

A

# Color is specified & taken into account for geom_half_point, but alignment is not suitable
ggplot(
  ToothGrowth %>%
    mutate(across(dose, as.character)),
  aes(x = dose, y = len)
) + 
  geom_half_boxplot() +
  geom_half_point(aes(color = supp)) +
  theme_bw()

B

My current issue is that some points are now over the boxplot. I'd like them to stay all on the right-hand side of the boxplot. Any tips ?

maciejmotyka commented 2 years ago

Use geom_half_point_panel() instead of geom_half_point().

From documentation:

Unlike 'geom_half_point', 'geom_half_point_panel' does not dodge different grouping aesthetics. This allows multiple groups in a single cloud of points

I was also confused by this. I colored by a variable with many levels and the result was a cloud of points similar to regular centered geom_jitter(). It took me much too long to figure this out.