[R] how to change the y-axis to logarithmic in a barplot ggplot

Maria Lathouri m|@thour| @end|ng |rom y@hoo@gr
Mon Jul 17 22:01:57 CEST 2023


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 using gmail.com> έγραψε: 





On Sun, 16 Jul 2023 21:51:10 +0000 (UTC)

Maria Lathouri via R-help <r-help using 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



More information about the R-help mailing list