Someone knows how to order the layers from the colour group? As 1 group is much smaller…

Someone knows how to order the layers from the colour group? As 1 group is much smaller…

Someone knows how to order the layers from the colour group? As 1 group is much smaller (but more important) I want to make sure that these dots are always on top of the much larger bulkier group.

ggplot2 order of layers when using aes(colour = group)
I have a (dense) dataset that consist out of 5 groups, so my data.frame looks something like x,y,group. I can plot this data and colour the points based on their group using: p= ggplot(dataset, aes(x,…

6 Replies to “Someone knows how to order the layers from the colour group? As 1 group is much smaller…”

  1. In general R plots, you can ensure that the important points are plotted on top by issueing the plot in a separate points command. I.e.
    plot(bulky.x, bulky.y)
    points(important.x, important.y, col="pink")

    But I am not familiar with ggplot, so it might not be transferable.

  2. In general R plots, you can ensure that the important points are plotted on top by issueing the plot in a separate points command. I.e.
    plot(bulky.x, bulky.y)
    points(important.x, important.y, col="pink")

    But I am not familiar with ggplot, so it might not be transferable.

  3. Yes, you can do the same trick inside ggplot but it's not the nicest of solutions. Especially because, as I found out now on stackoverflow, there is a way to force the order of points from your dataframe. Keeping your code much simpler and cleaner and especially if you have like 10+ categories much less redundant!

    BTW, you should move from base plot to ggplot2 – you'll see how much nicer your plots get 🙂

  4. Yes, you can do the same trick inside ggplot but it's not the nicest of solutions. Especially because, as I found out now on stackoverflow, there is a way to force the order of points from your dataframe. Keeping your code much simpler and cleaner and especially if you have like 10+ categories much less redundant!

    BTW, you should move from base plot to ggplot2 – you'll see how much nicer your plots get 🙂

Leave a Reply to Sander Timmer Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.