Adjust geom_point size so large values are plotted, but do not appear larger in ggplot2?












2















The issue I am having is that I would like the points above a certain threshold (=<25) to not produce points larger than the set scale. These larger points still need to be displayed, and cannot be excluded:



d=data.frame(y=c(1,2,6,4,4,6,7,8),
x=c(8,4,7,5,4,9,2,3),
coverage=c(0,6,9,88,25,22,17,100),
col=c(0,.25,.50,.76,.80,1.00,.11,.34)
)
ggplot() +
scale_size(range = c(0, 13),
breaks = c(0, 5, 10, 20, 25),
labels = c("0", "5", "10", "20", "25+"),
guide = "legend"
) +
geom_point(data = d, mapping = aes(x = x, y = y, color = col, size = coverage)) +
labs(title = "geom_point")


In the above sample code I have two points which have a "coverage" larger than 25+ and are outside of the scale. I would like these points to appear the same size as the 25+ threshold.



Example Plot output










share|improve this question




















  • 1





    The best option is likely to make a new variable that truncates coverage at 25 and use that for your size aesthetic.

    – zack
    Jan 2 at 22:21
















2















The issue I am having is that I would like the points above a certain threshold (=<25) to not produce points larger than the set scale. These larger points still need to be displayed, and cannot be excluded:



d=data.frame(y=c(1,2,6,4,4,6,7,8),
x=c(8,4,7,5,4,9,2,3),
coverage=c(0,6,9,88,25,22,17,100),
col=c(0,.25,.50,.76,.80,1.00,.11,.34)
)
ggplot() +
scale_size(range = c(0, 13),
breaks = c(0, 5, 10, 20, 25),
labels = c("0", "5", "10", "20", "25+"),
guide = "legend"
) +
geom_point(data = d, mapping = aes(x = x, y = y, color = col, size = coverage)) +
labs(title = "geom_point")


In the above sample code I have two points which have a "coverage" larger than 25+ and are outside of the scale. I would like these points to appear the same size as the 25+ threshold.



Example Plot output










share|improve this question




















  • 1





    The best option is likely to make a new variable that truncates coverage at 25 and use that for your size aesthetic.

    – zack
    Jan 2 at 22:21














2












2








2


1






The issue I am having is that I would like the points above a certain threshold (=<25) to not produce points larger than the set scale. These larger points still need to be displayed, and cannot be excluded:



d=data.frame(y=c(1,2,6,4,4,6,7,8),
x=c(8,4,7,5,4,9,2,3),
coverage=c(0,6,9,88,25,22,17,100),
col=c(0,.25,.50,.76,.80,1.00,.11,.34)
)
ggplot() +
scale_size(range = c(0, 13),
breaks = c(0, 5, 10, 20, 25),
labels = c("0", "5", "10", "20", "25+"),
guide = "legend"
) +
geom_point(data = d, mapping = aes(x = x, y = y, color = col, size = coverage)) +
labs(title = "geom_point")


In the above sample code I have two points which have a "coverage" larger than 25+ and are outside of the scale. I would like these points to appear the same size as the 25+ threshold.



Example Plot output










share|improve this question
















The issue I am having is that I would like the points above a certain threshold (=<25) to not produce points larger than the set scale. These larger points still need to be displayed, and cannot be excluded:



d=data.frame(y=c(1,2,6,4,4,6,7,8),
x=c(8,4,7,5,4,9,2,3),
coverage=c(0,6,9,88,25,22,17,100),
col=c(0,.25,.50,.76,.80,1.00,.11,.34)
)
ggplot() +
scale_size(range = c(0, 13),
breaks = c(0, 5, 10, 20, 25),
labels = c("0", "5", "10", "20", "25+"),
guide = "legend"
) +
geom_point(data = d, mapping = aes(x = x, y = y, color = col, size = coverage)) +
labs(title = "geom_point")


In the above sample code I have two points which have a "coverage" larger than 25+ and are outside of the scale. I would like these points to appear the same size as the 25+ threshold.



Example Plot output







r ggplot2 plot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 2:06









Z.Lin

13.3k22239




13.3k22239










asked Jan 2 at 22:18









Wealthy Oil TycoonWealthy Oil Tycoon

111




111








  • 1





    The best option is likely to make a new variable that truncates coverage at 25 and use that for your size aesthetic.

    – zack
    Jan 2 at 22:21














  • 1





    The best option is likely to make a new variable that truncates coverage at 25 and use that for your size aesthetic.

    – zack
    Jan 2 at 22:21








1




1





The best option is likely to make a new variable that truncates coverage at 25 and use that for your size aesthetic.

– zack
Jan 2 at 22:21





The best option is likely to make a new variable that truncates coverage at 25 and use that for your size aesthetic.

– zack
Jan 2 at 22:21












2 Answers
2






active

oldest

votes


















3














I think this is what you're looking for:



d %>%
mutate(coverage_trunc = pmin(coverage, 25)) %>%
ggplot() +
geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
labs(title="geom_point") +
scale_size(range=c(0,13),
breaks=c(0,5,10,20,25),
labels=c("0","5","10","20","25+"),
name = "Coverage Truncated",
guide="legend")


Picture of Truncated Coverage






share|improve this answer
























  • This is exactly what I was looking for. Thank you so much!

    – Wealthy Oil Tycoon
    Jan 2 at 23:38



















0














A ggplot only solution is to set the scale limits, and define the out of bounds behavior (oob) correctly. For size, one can use this scale:



ggplot(d, aes(x, y, color = col, size = coverage)) + 
geom_point() +
scale_size_area(
max_size = 13,
breaks = c(0,5,10,20,25),
labels = c("0","5","10","20","25+"),
guide = "legend",
limits = c(0, 25),
oob = scales::squish
)


enter image description here






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013902%2fadjust-geom-point-size-so-large-values-are-plotted-but-do-not-appear-larger-in%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    I think this is what you're looking for:



    d %>%
    mutate(coverage_trunc = pmin(coverage, 25)) %>%
    ggplot() +
    geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
    labs(title="geom_point") +
    scale_size(range=c(0,13),
    breaks=c(0,5,10,20,25),
    labels=c("0","5","10","20","25+"),
    name = "Coverage Truncated",
    guide="legend")


    Picture of Truncated Coverage






    share|improve this answer
























    • This is exactly what I was looking for. Thank you so much!

      – Wealthy Oil Tycoon
      Jan 2 at 23:38
















    3














    I think this is what you're looking for:



    d %>%
    mutate(coverage_trunc = pmin(coverage, 25)) %>%
    ggplot() +
    geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
    labs(title="geom_point") +
    scale_size(range=c(0,13),
    breaks=c(0,5,10,20,25),
    labels=c("0","5","10","20","25+"),
    name = "Coverage Truncated",
    guide="legend")


    Picture of Truncated Coverage






    share|improve this answer
























    • This is exactly what I was looking for. Thank you so much!

      – Wealthy Oil Tycoon
      Jan 2 at 23:38














    3












    3








    3







    I think this is what you're looking for:



    d %>%
    mutate(coverage_trunc = pmin(coverage, 25)) %>%
    ggplot() +
    geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
    labs(title="geom_point") +
    scale_size(range=c(0,13),
    breaks=c(0,5,10,20,25),
    labels=c("0","5","10","20","25+"),
    name = "Coverage Truncated",
    guide="legend")


    Picture of Truncated Coverage






    share|improve this answer













    I think this is what you're looking for:



    d %>%
    mutate(coverage_trunc = pmin(coverage, 25)) %>%
    ggplot() +
    geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
    labs(title="geom_point") +
    scale_size(range=c(0,13),
    breaks=c(0,5,10,20,25),
    labels=c("0","5","10","20","25+"),
    name = "Coverage Truncated",
    guide="legend")


    Picture of Truncated Coverage







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 2 at 22:31









    zackzack

    3,3941322




    3,3941322













    • This is exactly what I was looking for. Thank you so much!

      – Wealthy Oil Tycoon
      Jan 2 at 23:38



















    • This is exactly what I was looking for. Thank you so much!

      – Wealthy Oil Tycoon
      Jan 2 at 23:38

















    This is exactly what I was looking for. Thank you so much!

    – Wealthy Oil Tycoon
    Jan 2 at 23:38





    This is exactly what I was looking for. Thank you so much!

    – Wealthy Oil Tycoon
    Jan 2 at 23:38













    0














    A ggplot only solution is to set the scale limits, and define the out of bounds behavior (oob) correctly. For size, one can use this scale:



    ggplot(d, aes(x, y, color = col, size = coverage)) + 
    geom_point() +
    scale_size_area(
    max_size = 13,
    breaks = c(0,5,10,20,25),
    labels = c("0","5","10","20","25+"),
    guide = "legend",
    limits = c(0, 25),
    oob = scales::squish
    )


    enter image description here






    share|improve this answer




























      0














      A ggplot only solution is to set the scale limits, and define the out of bounds behavior (oob) correctly. For size, one can use this scale:



      ggplot(d, aes(x, y, color = col, size = coverage)) + 
      geom_point() +
      scale_size_area(
      max_size = 13,
      breaks = c(0,5,10,20,25),
      labels = c("0","5","10","20","25+"),
      guide = "legend",
      limits = c(0, 25),
      oob = scales::squish
      )


      enter image description here






      share|improve this answer


























        0












        0








        0







        A ggplot only solution is to set the scale limits, and define the out of bounds behavior (oob) correctly. For size, one can use this scale:



        ggplot(d, aes(x, y, color = col, size = coverage)) + 
        geom_point() +
        scale_size_area(
        max_size = 13,
        breaks = c(0,5,10,20,25),
        labels = c("0","5","10","20","25+"),
        guide = "legend",
        limits = c(0, 25),
        oob = scales::squish
        )


        enter image description here






        share|improve this answer













        A ggplot only solution is to set the scale limits, and define the out of bounds behavior (oob) correctly. For size, one can use this scale:



        ggplot(d, aes(x, y, color = col, size = coverage)) + 
        geom_point() +
        scale_size_area(
        max_size = 13,
        breaks = c(0,5,10,20,25),
        labels = c("0","5","10","20","25+"),
        guide = "legend",
        limits = c(0, 25),
        oob = scales::squish
        )


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 0:23









        AxemanAxeman

        19.3k54559




        19.3k54559






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013902%2fadjust-geom-point-size-so-large-values-are-plotted-but-do-not-appear-larger-in%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory