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

2023-07-17 Thread Kimmo Elo
Hi,

Have you tried:

scale_y_continuous(trans='log10')

HTH,

Kimmo

Lähettäjä: Maria Lathouri via R-help 
Lähetetty: maanantai 17. heinäkuuta 2023 23.01.57
Vastaanottaja: Maria Lathouri via R-help; Ivan Krylov
Aihe: Re: [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 
 έγραψε:





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

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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-17 Thread Maria Lathouri via R-help
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 
 έγραψε: 





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

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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-17 Thread Maria Lathouri via R-help
Dear Bert, 

Thank you very much for the tip. The reason that I took the initiative to write 
here is because I receive here as well questions about ggplot. Next time I will 
use the ggplot help. 

Maria






Στις Δευτέρα 17 Ιουλίου 2023 στις 12:20:25 π.μ. GMT+1, ο χρήστης Bert Gunter 
 έγραψε: 





Maria,

ggplot is part of the Posit -- formerly RStudio -- assortment of contributed 
packages. They have their own support site here , which you *may* find useful 
for such questions, also. Though ggplot queries *are* frequently posted and 
answered on R-Help.

Cheers,
Bert

On Sun, Jul 16, 2023 at 3:58 PM Maria Lathouri via R-help 
 wrote:
> I will find the ggplot help. 
> 
> But I have tried everything, including what you have suggested and nothing 
> works.
> 
> Kind regards,
> Maria
> 
> 
> 
> 
> 
> 
> Στις Κυριακή 16 Ιουλίου 2023 στις 11:22:36 μ.μ. GMT+1, ο χρήστης CALUM 
> POLWART  έγραψε: 
> 
> 
> 
> 
> 
> Try adding
> 
> scale_y_log10()
> 
> This is a general R help list. It's not a ggplot list and you are likely to 
> be chased off to ggplot's package maintainers nominated support pages.
> 
> But really a Google search should surely have found this?
> 
> 
> 
> On Sun, 16 Jul 2023, 22:51 Maria Lathouri via R-help,  
> wrote:
>> Dear all, 
>> 
>> ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) + 
>> geom_bar(stat = "identity", position = "dodge", aes(y=log(mean))) 
>> + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = 
>> element_blank()) + theme(legend.position = c(0.45, 0.85), legend.title = 
>> element_blank()) 
>> + scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette = 
>> "Dark2") +
>> 
> scale_y_log10()
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-17 Thread Kimmo Elo
Hi,

try:

scale_y_continuous(trans='log10')

HTH,

Kimmo
17. heinäk. 2023, 1.58, Maria Lathouri via R-help 
mailto:r-help@r-project.org>> kirjoitti:

I will find the ggplot help.

But I have tried everything, including what you have suggested and nothing 
works.

Kind regards,
Maria






Στις Κυριακή 16 Ιουλίου 2023 στις 11:22:36 μ.μ. GMT+1, ο χρήστης CALUM POLWART 
 έγραψε:





Try adding

scale_y_log10()

This is a general R help list. It's not a ggplot list and you are likely to be 
chased off to ggplot's package maintainers nominated support pages.

But really a Google search should surely have found this?



On Sun, 16 Jul 2023, 22:51 Maria Lathouri via R-help,  
wrote:
 Dear all,

 ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) +
 geom_bar(stat = "identity", position = "dodge", aes(y=log(mean)))
 + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = 
element_blank()) + theme(legend.position = c(0.45, 0.85), legend.title = 
element_blank())
 + scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette = "Dark2") 
+

scale_y_log10()



R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-16 Thread Ivan Krylov
On Sun, 16 Jul 2023 21:51:10 + (UTC)
Maria Lathouri via R-help  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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-16 Thread Bert Gunter
Maria,

ggplot is part of the Posit -- formerly RStudio -- assortment of
contributed packages. They have their own support site here
 , which you *may* find useful for such
questions, also. Though ggplot queries *are* frequently posted and answered
on R-Help.

Cheers,
Bert

On Sun, Jul 16, 2023 at 3:58 PM Maria Lathouri via R-help <
r-help@r-project.org> wrote:

> I will find the ggplot help.
>
> But I have tried everything, including what you have suggested and nothing
> works.
>
> Kind regards,
> Maria
>
>
>
>
>
>
> Στις Κυριακή 16 Ιουλίου 2023 στις 11:22:36 μ.μ. GMT+1, ο χρήστης CALUM
> POLWART  έγραψε:
>
>
>
>
>
> Try adding
>
> scale_y_log10()
>
> This is a general R help list. It's not a ggplot list and you are likely
> to be chased off to ggplot's package maintainers nominated support pages.
>
> But really a Google search should surely have found this?
>
>
>
> On Sun, 16 Jul 2023, 22:51 Maria Lathouri via R-help, <
> r-help@r-project.org> wrote:
> > Dear all,
> >
> > ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) +
> > geom_bar(stat = "identity", position = "dodge", aes(y=log(mean)))
> > + theme_bw() + theme(panel.grid.major = element_blank(),
> panel.grid.minor = element_blank()) + theme(legend.position = c(0.45,
> 0.85), legend.title = element_blank())
> > + scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette =
> "Dark2") +
> >
> scale_y_log10()
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-16 Thread CALUM POLWART
The data snippet doesn't make sense for the code you provided

Using the snippet I'd be doing

ggplot2(fc,  aes(x = ID, y= value)) +
geom_col() +
scale_y_log10()

And adjusting...

Not sure if that's what you are trying to do?


On Sun, 16 Jul 2023, 23:57 Maria Lathouri,  wrote:

> I will find the ggplot help.
>
> But I have tried everything, including what you have suggested and nothing
> works.
>
> Kind regards,
> Maria
>
>
>
>
>
>
> Στις Κυριακή 16 Ιουλίου 2023 στις 11:22:36 μ.μ. GMT+1, ο χρήστης CALUM
> POLWART  έγραψε:
>
>
>
>
>
> Try adding
>
> scale_y_log10()
>
> This is a general R help list. It's not a ggplot list and you are likely
> to be chased off to ggplot's package maintainers nominated support pages.
>
> But really a Google search should surely have found this?
>
>
>
> On Sun, 16 Jul 2023, 22:51 Maria Lathouri via R-help, <
> r-help@r-project.org> wrote:
> > Dear all,
> >
> > ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) +
> > geom_bar(stat = "identity", position = "dodge", aes(y=log(mean)))
> > + theme_bw() + theme(panel.grid.major = element_blank(),
> panel.grid.minor = element_blank()) + theme(legend.position = c(0.45,
> 0.85), legend.title = element_blank())
> > + scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette =
> "Dark2") +
> >
> scale_y_log10()
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-16 Thread Maria Lathouri via R-help
I will find the ggplot help. 

But I have tried everything, including what you have suggested and nothing 
works.

Kind regards,
Maria






Στις Κυριακή 16 Ιουλίου 2023 στις 11:22:36 μ.μ. GMT+1, ο χρήστης CALUM POLWART 
 έγραψε: 





Try adding

scale_y_log10()

This is a general R help list. It's not a ggplot list and you are likely to be 
chased off to ggplot's package maintainers nominated support pages.

But really a Google search should surely have found this?



On Sun, 16 Jul 2023, 22:51 Maria Lathouri via R-help,  
wrote:
> Dear all, 
> 
> ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) + 
> geom_bar(stat = "identity", position = "dodge", aes(y=log(mean))) 
> + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = 
> element_blank()) + theme(legend.position = c(0.45, 0.85), legend.title = 
> element_blank()) 
> + scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette = 
> "Dark2") +
> 
scale_y_log10()

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-16 Thread CALUM POLWART
Try adding

scale_y_log10()

This is a general R help list. It's not a ggplot list and you are likely to
be chased off to ggplot's package maintainers nominated support pages.

But really a Google search should surely have found this?



On Sun, 16 Jul 2023, 22:51 Maria Lathouri via R-help, 
wrote:

> Dear all,
>
> ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) +
> geom_bar(stat = "identity", position = "dodge", aes(y=log(mean)))
> + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor
> = element_blank()) + theme(legend.position = c(0.45, 0.85), legend.title =
> element_blank())
> + scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette =
> "Dark2") +
>
scale_y_log10()

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-16 Thread David Winsemius



On 7/16/23 14:51, Maria Lathouri via R-help wrote:

Dear all,


I am having the following dataset
fc<-
ID    values    databases
Al    0.15    phreeqc
Al    0.6    carbfix
Al    0.47    actual
Ca    7.2    phreeqc
Ca    7.2    carbfix
Ca    0.3    actual
Na    14.4    phreeqc
Na    84    carbfix
Na    106    actual
Cl    22    phreeqc
Cl    21.9    carbfix
Cl    72.1    actual
Fe    0.05    phreeqc
Fe    0.43    carbfix
Fe    1.25    actual
Mg    0.35    phreeqc
Mg    0.17    carbfix
Mg    0.08    actual
SO4    0    phreeqc
SO4    0    carbfix
SO4    416    actual


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. So I am trying to make the y axis logarithmic. I have created the 
following code but it doesn't work. I get the bars with zero above and the 
others on top.


ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) +



None of those aes() names are in your data object. They should be one of

ID    values    databases



geom_bar(stat = "identity", position = "dodge", aes(y=log(mean)))


What are you intending with `

aes(y=log(mean)

`

+ theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = 
element_blank()) + theme(legend.position = c(0.45, 0.85), legend.title = 
element_blank())
+ scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette = "Dark2")


--

David.



I would very much appreciate your help. I am stuck.


Kind regards,
Maria

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2023-07-16 Thread Maria Lathouri via R-help
Dear all, 


I am having the following dataset
fc<-
ID    values    databases
Al    0.15    phreeqc
Al    0.6    carbfix
Al    0.47    actual
Ca    7.2    phreeqc
Ca    7.2    carbfix
Ca    0.3    actual
Na    14.4    phreeqc
Na    84    carbfix
Na    106    actual
Cl    22    phreeqc
Cl    21.9    carbfix
Cl    72.1    actual
Fe    0.05    phreeqc
Fe    0.43    carbfix
Fe    1.25    actual
Mg    0.35    phreeqc
Mg    0.17    carbfix
Mg    0.08    actual
SO4    0    phreeqc
SO4    0    carbfix
SO4    416    actual


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. So I am trying to make the y axis logarithmic. I have created the 
following code but it doesn't work. I get the bars with zero above and the 
others on top. 


ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) + 
geom_bar(stat = "identity", position = "dodge", aes(y=log(mean))) 
+ theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = 
element_blank()) + theme(legend.position = c(0.45, 0.85), legend.title = 
element_blank()) 
+ scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette = "Dark2")


I would very much appreciate your help. I am stuck. 


Kind regards,
Maria

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.