Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_boxjitter: can we skip drawing the jitter points? #4

Closed
tungmilan opened this issue May 19, 2019 · 8 comments
Closed

geom_boxjitter: can we skip drawing the jitter points? #4

tungmilan opened this issue May 19, 2019 · 8 comments
Assignees
Labels

Comments

@tungmilan
Copy link

@tungmilan tungmilan commented May 19, 2019

Hello,

I want to keep only the half boxplot and replace the jitter points with the points from the ggbeeswarm package. Is it possible? Could you add an option to turn on/off the plotting of all the points?

In the example below, I can disable the color of all the jitter points but it leaves an empty space between the boxplot and the beeswarm.

Thanks!

library(ggplot2)
library(ggbeeswarm)
library(ggpol)

ggplot(iris, aes(y = Petal.Width)) + 
  geom_boxjitter(jitter.shape = NA, 
                 jitter.color = NA,
                 jitter.height = 0, 
                 jitter.width = 0,
                 outlier.color = NA, 
                 errorbar.draw = TRUE) +
  geom_quasirandom(
    aes(x = 1, color = Species),
    width = 0.25,
    size = 2, 
    groupOnX = TRUE, alpha = 0.7) +
  scale_color_brewer(palette = 'Set2') +
  theme_classic()

Created on 2019-05-18 by the reprex package (v0.3.0)

@tungmilan tungmilan changed the title geom_boxjitter: can we skip drawing the the jitter points? geom_boxjitter: can we skip drawing the jitter points? May 19, 2019
@erocoar erocoar added the enhancement label May 19, 2019
@erocoar erocoar self-assigned this May 19, 2019
@erocoar
Copy link
Owner

@erocoar erocoar commented May 19, 2019

It's a bit more difficult than that because while only half the boxplot is shown, it takes up an entire factor on the scales together with the points. But I like the general idea so I am considering changing up the function arguments a bit. With a9496e9 you can pass on a Position class (defaults to PositionDodge).

In this case:

ggplot(iris, aes(y = Petal.Width)) +
  geom_boxjitter(jitter.position = ggbeeswarm:::PositionQuasirandom, 
                  jitter.params = formals(position_quasirandom)) +
  theme_classic()

Rplot

@tungmilan
Copy link
Author

@tungmilan tungmilan commented May 19, 2019

Thanks for the quick update! Can you color different species (as in my example) too?

@erocoar
Copy link
Owner

@erocoar erocoar commented May 20, 2019

I have to think about how to implement that in a user-friendly way. I could imagine passing a vector to jitter.color, but I don't think it will be possible to use scale_color_ for this. Will update later.

@erocoar
Copy link
Owner

@erocoar erocoar commented Jun 12, 2019

Getting back to this: It seems rather pointless to implement without also properly implementing color (, fill, alpha, shape) scales. Right now the geom calls pointsGrob directly. I'll need to do some more reading into the source code to see how I can implement that. Potentially with a new geom_half_half.

@tungmilan
Copy link
Author

@tungmilan tungmilan commented Jun 12, 2019

@erocoar : thanks for the update!

@tungmilan
Copy link
Author

@tungmilan tungmilan commented Jul 2, 2019

@erocoar : Hi this is off topic but how can you control the width of the boxplot? I tried width = ... but it changed the width of the point spreading. Thanks!

@erocoar
Copy link
Owner

@erocoar erocoar commented Sep 13, 2019

Okay so for the geom_quasirandom issue, could you check out whether geom_half_boxplot from gghalves package works for you and otherwise file an issue there with the specific functionality you'd like to see? It should work for your example, but probably not when you have multiple x values.

For the width, it should (and does for me) change the width of both boxplot and point spreading. Is that the case for you too?

@tungmilan
Copy link
Author

@tungmilan tungmilan commented Sep 13, 2019

Great! Thanks for working on this! I'll try it as soon as I can

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.