0

I have a day/time dotplot a series of attributes. I'm changing the color of a specific attribute to make it stand out from the set. However, it seems like no matter what I do, most of the dots will "hide" behind the other "non-relevant" datapoints. How can I change the layer priority of the bluegreen dots to always be "on top"?

Here's what my plot looks like.

enter image description here

And here's the code i use to generate it in shiny.

  output$timdat <- renderPlot({
        pasx2$color <- factor(ifelse(pasx2$pasx.BFTYPE == input$BFTYPESEL,'Selection','Dataset'))
        ggplot(pasx2, aes(pasx.day, pasx.time, colour=color)) +
          geom_jitter() + scale_x_discrete("Day") + 
          scale_y_discrete("Time")})

BFTYPESEL is a list of possible "terms" to isolate from the main dataframe. One is selected. color is a factor with 2 levels in my dataframe that is updated to discriminate one term from the set.

  • 1
    try adjusting `alpha` – mtoto Jan 26 '16 at 09:38
  • How can I only adjust the alpha of one of the two colors? Otherwise the problem will persist, as there are more red then blue dots. – Roeben Vink Jan 26 '16 at 09:42
  • 3
    One possibility would be to make two calls to `geom_jitter` where you use the `data` argument and plot the two subsets of the data in your desired order. And as always: make sure to post a _minimal, self-contained_ example to make it easier for people to try their code (easier ~~> more willing to help). – Henrik Jan 26 '16 at 09:42
  • 2
    It's a really nice graph. It's cool you are able to put all your points on one graph. But have you though about doing a (double) violin plot as well? It may be more practical for your analysis. – YCR Jan 26 '16 at 09:45
  • Also [see here](http://www.r-bloggers.com/how-to-change-the-alpha-value-of-colours-in-r/) for an example how to define colors with alpha transparency. Or you can also add `alpha = color` to your `aes`. – Axeman Jan 26 '16 at 09:53
  • @Henrik I'll keep that feedback in mind the next time I ask a question. Does using two geom_jitter with a data argument also work for specific levels within the factor? I might look into the violin plot option, as well, though right now I'd really like to combine all datapoints into one representation. – Roeben Vink Jan 26 '16 at 09:57
  • Regarding reproducible example, check e.g. [**here**](http://stackoverflow.com/help/mcve) and [**here**](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). I'm not sure what you mean by "Does using two geom_jitter with a data argument also work for specific levels within the factor?" You can use "any" subset of your data. – Henrik Jan 26 '16 at 10:06

0 Answers0