1

I want to set my y-axis to log-scale to make the visualization better readable.

Before doing so my data looks correctly displayed . without log-scale

plot_bar(ent40, "phylum", fill="kingdom", facet_grid=~sampleID)+
geom_col(aes(fill=kingdom), position="stack")+
  scale_y_continuous(labels = comma_format(big.mark = ".", decimal.mark = ","))

When I change it to log-scale on y-axis I get the following error messages:

Warning messages:
1: Transformation introduced infinite values in continuous y-axis 
2: Transformation introduced infinite values in continuous y-axis 
3: Removed 119 rows containing missing values (geom_bar). 
4: Removed 119 rows containing missing values (geom_col).

On top my plot's scale gets completely out of proportion.

after transformation

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
mr.raccoon
  • 47
  • 7
  • 1
    Round the values to a specific number of decimal places; that should solve the problem. – Kat Apr 13 '21 at 15:10
  • The strange thing is: my values are "whole numbers". – mr.raccoon Apr 14 '21 at 12:40
  • 1
    The data won't be whole numbers after calculating the logarithm. – Kat Apr 15 '21 at 00:39
  • Where do I add an argument to round the values than? – mr.raccoon Apr 15 '21 at 12:07
  • 1
    You don't have it in the code where you took the `log`, and I don't know how you're going to use the data next, but this you can round where you calculated the logarithm. This is an example: `round(log(runif(10, 100, 1000)), digits = 2)`. I'm just using `runif()` here to create random numbers. This rounds to two decimals places. – Kat Apr 15 '21 at 16:41
  • For the danger of asking a complete stupid question. I think I am really stuck: my goal is to just transform the y-axis in order to compare samples better that have a wide range of observations. So I don't want to tansform my actual values just the scales. – mr.raccoon Apr 16 '21 at 10:56
  • `plot_bar(ent40, "phylum", fill="kingdom", facet_grid=~sampleID)+ geom_col(aes(fill=kingdom), position="stack")+ scale_y_log10(labels = comma_format(big.mark = ".", decimal.mark = ","))` I just wanted a log_scale. Is this the wrong approach? – mr.raccoon Apr 16 '21 at 11:21
  • You can scale the data within the graph only without actually changing your data. From the images you provided, it seems like using the log scale may be a good idea. Is the data exponential? If you want a better answer, add some data to your post: use `dput()`. Alternatively, I would encourage you to see what the data looks like when you take the log outside the graph. – Kat Apr 17 '21 at 01:27

0 Answers0