Plot function only plots one amount in this dataframe. What could be the reason?












-1















I have created a long format dataframe



  Category           Amount
1 Angry 0.00000010230325
2 Fear 0.00000007393743
3 Happy 0.99942147731781
4 Neutral 0.00057571416255
5 Sad 0.00000002021321
6 Surprise 0.00000260657316


And the code is:



library(tidyverse)
library(ggplot2)
# There are plenty of ways to reshape the data frame,
# but I think `tidyr::gather()` is the easiest
dfr_long <- gather(dfr, key = "Category", value = "Amount")
ggplot(data = dfr_long, aes(x = Category, y = Amount)) +
geom_bar(stat = "identity")


However, as you see in the image, only Happy gets plotted and the rest are all in same level. I even tried to change the ylim to c(-1,0.99) but the plot still looks the same. How can I fix this?



plot










share|improve this question




















  • 2





    The value for happy is greater than 0.999. All other values are less than 0.001. You cannot expect to see those small values in a plot that is scaled 0 to 1. The other values should be less than 1/1000 the height of happy.

    – G5W
    Nov 26 '18 at 0:18













  • @neilfws I tried to change the ylim values but it still wouldnt plot. Is it not possible at all to plot such values?

    – codeybanks
    Nov 26 '18 at 0:22






  • 1





    They are being plotted. They're just minuscule. You can try + scale_y_continuous(trans = "sqrt") but you then need to make sure you note the transformation in the plot labels.

    – hrbrmstr
    Nov 26 '18 at 0:24













  • The issue is the scale, as @G5W pointed out. You could try a log scale, e.g. + scale_y_log10(), but then bars will not be appropriate, you could try points instead.

    – neilfws
    Nov 26 '18 at 0:26








  • 1





    @neilfws or multiply Amount by ~100000000 and use log10 and change the Y labels and add alot of notes about the transformation :-) @codeybanks we don't really know what these values represent but I'd suggest the values of the other categories are so small that they may be nigh irrelevant.

    – hrbrmstr
    Nov 26 '18 at 0:29
















-1















I have created a long format dataframe



  Category           Amount
1 Angry 0.00000010230325
2 Fear 0.00000007393743
3 Happy 0.99942147731781
4 Neutral 0.00057571416255
5 Sad 0.00000002021321
6 Surprise 0.00000260657316


And the code is:



library(tidyverse)
library(ggplot2)
# There are plenty of ways to reshape the data frame,
# but I think `tidyr::gather()` is the easiest
dfr_long <- gather(dfr, key = "Category", value = "Amount")
ggplot(data = dfr_long, aes(x = Category, y = Amount)) +
geom_bar(stat = "identity")


However, as you see in the image, only Happy gets plotted and the rest are all in same level. I even tried to change the ylim to c(-1,0.99) but the plot still looks the same. How can I fix this?



plot










share|improve this question




















  • 2





    The value for happy is greater than 0.999. All other values are less than 0.001. You cannot expect to see those small values in a plot that is scaled 0 to 1. The other values should be less than 1/1000 the height of happy.

    – G5W
    Nov 26 '18 at 0:18













  • @neilfws I tried to change the ylim values but it still wouldnt plot. Is it not possible at all to plot such values?

    – codeybanks
    Nov 26 '18 at 0:22






  • 1





    They are being plotted. They're just minuscule. You can try + scale_y_continuous(trans = "sqrt") but you then need to make sure you note the transformation in the plot labels.

    – hrbrmstr
    Nov 26 '18 at 0:24













  • The issue is the scale, as @G5W pointed out. You could try a log scale, e.g. + scale_y_log10(), but then bars will not be appropriate, you could try points instead.

    – neilfws
    Nov 26 '18 at 0:26








  • 1





    @neilfws or multiply Amount by ~100000000 and use log10 and change the Y labels and add alot of notes about the transformation :-) @codeybanks we don't really know what these values represent but I'd suggest the values of the other categories are so small that they may be nigh irrelevant.

    – hrbrmstr
    Nov 26 '18 at 0:29














-1












-1








-1








I have created a long format dataframe



  Category           Amount
1 Angry 0.00000010230325
2 Fear 0.00000007393743
3 Happy 0.99942147731781
4 Neutral 0.00057571416255
5 Sad 0.00000002021321
6 Surprise 0.00000260657316


And the code is:



library(tidyverse)
library(ggplot2)
# There are plenty of ways to reshape the data frame,
# but I think `tidyr::gather()` is the easiest
dfr_long <- gather(dfr, key = "Category", value = "Amount")
ggplot(data = dfr_long, aes(x = Category, y = Amount)) +
geom_bar(stat = "identity")


However, as you see in the image, only Happy gets plotted and the rest are all in same level. I even tried to change the ylim to c(-1,0.99) but the plot still looks the same. How can I fix this?



plot










share|improve this question
















I have created a long format dataframe



  Category           Amount
1 Angry 0.00000010230325
2 Fear 0.00000007393743
3 Happy 0.99942147731781
4 Neutral 0.00057571416255
5 Sad 0.00000002021321
6 Surprise 0.00000260657316


And the code is:



library(tidyverse)
library(ggplot2)
# There are plenty of ways to reshape the data frame,
# but I think `tidyr::gather()` is the easiest
dfr_long <- gather(dfr, key = "Category", value = "Amount")
ggplot(data = dfr_long, aes(x = Category, y = Amount)) +
geom_bar(stat = "identity")


However, as you see in the image, only Happy gets plotted and the rest are all in same level. I even tried to change the ylim to c(-1,0.99) but the plot still looks the same. How can I fix this?



plot







r dataframe ggplot2 tidyverse






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 0:18









neilfws

18.2k53749




18.2k53749










asked Nov 26 '18 at 0:15









codeybankscodeybanks

205




205








  • 2





    The value for happy is greater than 0.999. All other values are less than 0.001. You cannot expect to see those small values in a plot that is scaled 0 to 1. The other values should be less than 1/1000 the height of happy.

    – G5W
    Nov 26 '18 at 0:18













  • @neilfws I tried to change the ylim values but it still wouldnt plot. Is it not possible at all to plot such values?

    – codeybanks
    Nov 26 '18 at 0:22






  • 1





    They are being plotted. They're just minuscule. You can try + scale_y_continuous(trans = "sqrt") but you then need to make sure you note the transformation in the plot labels.

    – hrbrmstr
    Nov 26 '18 at 0:24













  • The issue is the scale, as @G5W pointed out. You could try a log scale, e.g. + scale_y_log10(), but then bars will not be appropriate, you could try points instead.

    – neilfws
    Nov 26 '18 at 0:26








  • 1





    @neilfws or multiply Amount by ~100000000 and use log10 and change the Y labels and add alot of notes about the transformation :-) @codeybanks we don't really know what these values represent but I'd suggest the values of the other categories are so small that they may be nigh irrelevant.

    – hrbrmstr
    Nov 26 '18 at 0:29














  • 2





    The value for happy is greater than 0.999. All other values are less than 0.001. You cannot expect to see those small values in a plot that is scaled 0 to 1. The other values should be less than 1/1000 the height of happy.

    – G5W
    Nov 26 '18 at 0:18













  • @neilfws I tried to change the ylim values but it still wouldnt plot. Is it not possible at all to plot such values?

    – codeybanks
    Nov 26 '18 at 0:22






  • 1





    They are being plotted. They're just minuscule. You can try + scale_y_continuous(trans = "sqrt") but you then need to make sure you note the transformation in the plot labels.

    – hrbrmstr
    Nov 26 '18 at 0:24













  • The issue is the scale, as @G5W pointed out. You could try a log scale, e.g. + scale_y_log10(), but then bars will not be appropriate, you could try points instead.

    – neilfws
    Nov 26 '18 at 0:26








  • 1





    @neilfws or multiply Amount by ~100000000 and use log10 and change the Y labels and add alot of notes about the transformation :-) @codeybanks we don't really know what these values represent but I'd suggest the values of the other categories are so small that they may be nigh irrelevant.

    – hrbrmstr
    Nov 26 '18 at 0:29








2




2





The value for happy is greater than 0.999. All other values are less than 0.001. You cannot expect to see those small values in a plot that is scaled 0 to 1. The other values should be less than 1/1000 the height of happy.

– G5W
Nov 26 '18 at 0:18







The value for happy is greater than 0.999. All other values are less than 0.001. You cannot expect to see those small values in a plot that is scaled 0 to 1. The other values should be less than 1/1000 the height of happy.

– G5W
Nov 26 '18 at 0:18















@neilfws I tried to change the ylim values but it still wouldnt plot. Is it not possible at all to plot such values?

– codeybanks
Nov 26 '18 at 0:22





@neilfws I tried to change the ylim values but it still wouldnt plot. Is it not possible at all to plot such values?

– codeybanks
Nov 26 '18 at 0:22




1




1





They are being plotted. They're just minuscule. You can try + scale_y_continuous(trans = "sqrt") but you then need to make sure you note the transformation in the plot labels.

– hrbrmstr
Nov 26 '18 at 0:24







They are being plotted. They're just minuscule. You can try + scale_y_continuous(trans = "sqrt") but you then need to make sure you note the transformation in the plot labels.

– hrbrmstr
Nov 26 '18 at 0:24















The issue is the scale, as @G5W pointed out. You could try a log scale, e.g. + scale_y_log10(), but then bars will not be appropriate, you could try points instead.

– neilfws
Nov 26 '18 at 0:26







The issue is the scale, as @G5W pointed out. You could try a log scale, e.g. + scale_y_log10(), but then bars will not be appropriate, you could try points instead.

– neilfws
Nov 26 '18 at 0:26






1




1





@neilfws or multiply Amount by ~100000000 and use log10 and change the Y labels and add alot of notes about the transformation :-) @codeybanks we don't really know what these values represent but I'd suggest the values of the other categories are so small that they may be nigh irrelevant.

– hrbrmstr
Nov 26 '18 at 0:29





@neilfws or multiply Amount by ~100000000 and use log10 and change the Y labels and add alot of notes about the transformation :-) @codeybanks we don't really know what these values represent but I'd suggest the values of the other categories are so small that they may be nigh irrelevant.

– hrbrmstr
Nov 26 '18 at 0:29












1 Answer
1






active

oldest

votes


















1














Since your claim against my comment was woefully incorrect:



read.table(text="Category           Amount
Angry 0.00000010230325
Fear 0.00000007393743
Happy 0.99942147731781
Neutral 0.00057571416255
Sad 0.00000002021321
Surprise 0.00000260657316", header=TRUE, stringsAsFactors=FALSE) -> dfr

ggplot(data = dfr, aes(x = Category, y = 100000000*Amount)) +
geom_bar(stat = "identity") +
scale_y_continuous(trans = "log10")


enter image description here



NOTE that ^^ seriously misrepresents the data and requires a ton of labeling to make sure your readers do not misinterpret it.



This:



ggplot(data = dfr, aes(x = Category, y = Amount)) +
geom_bar(stat = "identity") +
scale_y_continuous(trans = "sqrt")


enter image description here



is somewhat better but still requires you to do a substantial amount of labeling to ensure the data is not being misrepresented.



This:



options(scipen = 999)

dplyr::arrange(dfr, desc(Amount)) %>%
mutate(Category = factor(Category, levels = Category)) %>%
mutate(txt_col = dplyr::case_when(
Category == "Happy" ~ "white",
TRUE ~ "black"
)) %>%
ggplot(aes(x = Category, y = 1)) +
geom_tile(aes(fill = Amount), color = "white", size=0.125) +
geom_text(aes(label = Amount, color = I(txt_col)), size=2.5) +
viridis::scale_fill_viridis(direction = -1) +
coord_equal() +
labs(
x = NULL, y = NULL
) +
hrbrthemes::theme_ipsum_rc(grid="") +
theme(axis.text.y = element_blank())


enter image description here



is an alternate way to show the data but it's no more effective than a basic, ordered table would be IMO.






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%2f53473309%2fplot-function-only-plots-one-amount-in-this-dataframe-what-could-be-the-reason%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Since your claim against my comment was woefully incorrect:



    read.table(text="Category           Amount
    Angry 0.00000010230325
    Fear 0.00000007393743
    Happy 0.99942147731781
    Neutral 0.00057571416255
    Sad 0.00000002021321
    Surprise 0.00000260657316", header=TRUE, stringsAsFactors=FALSE) -> dfr

    ggplot(data = dfr, aes(x = Category, y = 100000000*Amount)) +
    geom_bar(stat = "identity") +
    scale_y_continuous(trans = "log10")


    enter image description here



    NOTE that ^^ seriously misrepresents the data and requires a ton of labeling to make sure your readers do not misinterpret it.



    This:



    ggplot(data = dfr, aes(x = Category, y = Amount)) +
    geom_bar(stat = "identity") +
    scale_y_continuous(trans = "sqrt")


    enter image description here



    is somewhat better but still requires you to do a substantial amount of labeling to ensure the data is not being misrepresented.



    This:



    options(scipen = 999)

    dplyr::arrange(dfr, desc(Amount)) %>%
    mutate(Category = factor(Category, levels = Category)) %>%
    mutate(txt_col = dplyr::case_when(
    Category == "Happy" ~ "white",
    TRUE ~ "black"
    )) %>%
    ggplot(aes(x = Category, y = 1)) +
    geom_tile(aes(fill = Amount), color = "white", size=0.125) +
    geom_text(aes(label = Amount, color = I(txt_col)), size=2.5) +
    viridis::scale_fill_viridis(direction = -1) +
    coord_equal() +
    labs(
    x = NULL, y = NULL
    ) +
    hrbrthemes::theme_ipsum_rc(grid="") +
    theme(axis.text.y = element_blank())


    enter image description here



    is an alternate way to show the data but it's no more effective than a basic, ordered table would be IMO.






    share|improve this answer






























      1














      Since your claim against my comment was woefully incorrect:



      read.table(text="Category           Amount
      Angry 0.00000010230325
      Fear 0.00000007393743
      Happy 0.99942147731781
      Neutral 0.00057571416255
      Sad 0.00000002021321
      Surprise 0.00000260657316", header=TRUE, stringsAsFactors=FALSE) -> dfr

      ggplot(data = dfr, aes(x = Category, y = 100000000*Amount)) +
      geom_bar(stat = "identity") +
      scale_y_continuous(trans = "log10")


      enter image description here



      NOTE that ^^ seriously misrepresents the data and requires a ton of labeling to make sure your readers do not misinterpret it.



      This:



      ggplot(data = dfr, aes(x = Category, y = Amount)) +
      geom_bar(stat = "identity") +
      scale_y_continuous(trans = "sqrt")


      enter image description here



      is somewhat better but still requires you to do a substantial amount of labeling to ensure the data is not being misrepresented.



      This:



      options(scipen = 999)

      dplyr::arrange(dfr, desc(Amount)) %>%
      mutate(Category = factor(Category, levels = Category)) %>%
      mutate(txt_col = dplyr::case_when(
      Category == "Happy" ~ "white",
      TRUE ~ "black"
      )) %>%
      ggplot(aes(x = Category, y = 1)) +
      geom_tile(aes(fill = Amount), color = "white", size=0.125) +
      geom_text(aes(label = Amount, color = I(txt_col)), size=2.5) +
      viridis::scale_fill_viridis(direction = -1) +
      coord_equal() +
      labs(
      x = NULL, y = NULL
      ) +
      hrbrthemes::theme_ipsum_rc(grid="") +
      theme(axis.text.y = element_blank())


      enter image description here



      is an alternate way to show the data but it's no more effective than a basic, ordered table would be IMO.






      share|improve this answer




























        1












        1








        1







        Since your claim against my comment was woefully incorrect:



        read.table(text="Category           Amount
        Angry 0.00000010230325
        Fear 0.00000007393743
        Happy 0.99942147731781
        Neutral 0.00057571416255
        Sad 0.00000002021321
        Surprise 0.00000260657316", header=TRUE, stringsAsFactors=FALSE) -> dfr

        ggplot(data = dfr, aes(x = Category, y = 100000000*Amount)) +
        geom_bar(stat = "identity") +
        scale_y_continuous(trans = "log10")


        enter image description here



        NOTE that ^^ seriously misrepresents the data and requires a ton of labeling to make sure your readers do not misinterpret it.



        This:



        ggplot(data = dfr, aes(x = Category, y = Amount)) +
        geom_bar(stat = "identity") +
        scale_y_continuous(trans = "sqrt")


        enter image description here



        is somewhat better but still requires you to do a substantial amount of labeling to ensure the data is not being misrepresented.



        This:



        options(scipen = 999)

        dplyr::arrange(dfr, desc(Amount)) %>%
        mutate(Category = factor(Category, levels = Category)) %>%
        mutate(txt_col = dplyr::case_when(
        Category == "Happy" ~ "white",
        TRUE ~ "black"
        )) %>%
        ggplot(aes(x = Category, y = 1)) +
        geom_tile(aes(fill = Amount), color = "white", size=0.125) +
        geom_text(aes(label = Amount, color = I(txt_col)), size=2.5) +
        viridis::scale_fill_viridis(direction = -1) +
        coord_equal() +
        labs(
        x = NULL, y = NULL
        ) +
        hrbrthemes::theme_ipsum_rc(grid="") +
        theme(axis.text.y = element_blank())


        enter image description here



        is an alternate way to show the data but it's no more effective than a basic, ordered table would be IMO.






        share|improve this answer















        Since your claim against my comment was woefully incorrect:



        read.table(text="Category           Amount
        Angry 0.00000010230325
        Fear 0.00000007393743
        Happy 0.99942147731781
        Neutral 0.00057571416255
        Sad 0.00000002021321
        Surprise 0.00000260657316", header=TRUE, stringsAsFactors=FALSE) -> dfr

        ggplot(data = dfr, aes(x = Category, y = 100000000*Amount)) +
        geom_bar(stat = "identity") +
        scale_y_continuous(trans = "log10")


        enter image description here



        NOTE that ^^ seriously misrepresents the data and requires a ton of labeling to make sure your readers do not misinterpret it.



        This:



        ggplot(data = dfr, aes(x = Category, y = Amount)) +
        geom_bar(stat = "identity") +
        scale_y_continuous(trans = "sqrt")


        enter image description here



        is somewhat better but still requires you to do a substantial amount of labeling to ensure the data is not being misrepresented.



        This:



        options(scipen = 999)

        dplyr::arrange(dfr, desc(Amount)) %>%
        mutate(Category = factor(Category, levels = Category)) %>%
        mutate(txt_col = dplyr::case_when(
        Category == "Happy" ~ "white",
        TRUE ~ "black"
        )) %>%
        ggplot(aes(x = Category, y = 1)) +
        geom_tile(aes(fill = Amount), color = "white", size=0.125) +
        geom_text(aes(label = Amount, color = I(txt_col)), size=2.5) +
        viridis::scale_fill_viridis(direction = -1) +
        coord_equal() +
        labs(
        x = NULL, y = NULL
        ) +
        hrbrthemes::theme_ipsum_rc(grid="") +
        theme(axis.text.y = element_blank())


        enter image description here



        is an alternate way to show the data but it's no more effective than a basic, ordered table would be IMO.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 26 '18 at 0:51

























        answered Nov 26 '18 at 0:42









        hrbrmstrhrbrmstr

        61.5k691152




        61.5k691152
































            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%2f53473309%2fplot-function-only-plots-one-amount-in-this-dataframe-what-could-be-the-reason%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

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'