Ivan Krylov
2023-Jul-17 03:43 UTC
[R] how to change the y-axis to logarithmic in a barplot ggplot
On Sun, 16 Jul 2023 21:51:10 +0000 (UTC) Maria Lathouri via R-help <r-help at r-project.org> wrote:> As you can see, the values range from 0 to 400. I want it to plot it > in bars; when I am plotting it as you can imagine the values near > zero don't show at all.A logarithmic scale won't work when the range of numbers to display includes 0. It would have worked if it was some small non-zero quantity, but an actual zero is infinitely far down; it won't fit. There is a number of transformations described in help(scale_y_continuous). You may find trans="pseudo_log" or trans="sqrt" useful. help(geom_bar) recommends geom_col() instead of geom_bar() to represent values (not counts of occurrences). We could help you more efficiently if you clarified the relationship between your data (with columns `ID`, `values`, `databases`) and your code (which mentions `Temp`, `mean`, `Glass`). -- Best regards, Ivan
Maria Lathouri
2023-Jul-17 20:01 UTC
[R] how to change the y-axis to logarithmic in a barplot ggplot
Hi Ivan,? yes you are right. I have many values close to zero and if I use log, they are instantly transformed to negative values and then the bars show above. The sqrt trans worked ok but when I used the pseudo_log_trans, it did the work! Many thanks.? Kind regards, Maria ???? ??????? 17 ??????? 2023 ???? 04:43:59 ?.?. GMT+1, ? ??????? Ivan Krylov <krylov.r00t at gmail.com> ??????: On Sun, 16 Jul 2023 21:51:10 +0000 (UTC) Maria Lathouri via R-help <r-help at r-project.org> wrote:> As you can see, the values range from 0 to 400. I want it to plot it > in bars; when I am plotting it as you can imagine the values near > zero don't show at all.A logarithmic scale won't work when the range of numbers to display includes 0. It would have worked if it was some small non-zero quantity, but an actual zero is infinitely far down; it won't fit. There is a number of transformations described in help(scale_y_continuous). You may find trans="pseudo_log" or trans="sqrt" useful. help(geom_bar) recommends geom_col() instead of geom_bar() to represent values (not counts of occurrences). We could help you more efficiently if you clarified the relationship between your data (with columns `ID`, `values`, `databases`) and your code (which mentions `Temp`, `mean`, `Glass`). -- Best regards, Ivan