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

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Mon Jul 17 00:21:33 CEST 2023


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 using 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.



More information about the R-help mailing list