0

Current code outputs a stacked bar graph of species at different sites. Im looking to log10 the y axis to provide a more concise view. And adjust y axis tick labels accordingly so it reads the log10 numbers.

I have already tried scale_y_log10 including different breaks and labels but have had limited success

species<-read.table('species.txt',header=TRUE)
library(ggplot2)
ggplot(species, aes(x = site, y = number, fill = species)) + 
  geom_bar(stat = "identity")+
  theme(legend.position="none")+
  labs(y="Number of Individuals",x="Sites")
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
c_dev
  • 65
  • 8
  • 1
    Can you provide `dput(species)` ? – Ronak Shah Apr 24 '19 at 01:54
  • 3
    A log scale doesn't really make sense for a bar plot (see [here](https://stackoverflow.com/questions/46639120/transform-y-axis-in-bar-plot-using-scale-y-log10/46664684) for example). If you provide sample data, we might be able to suggest other options. – eipi10 Apr 24 '19 at 02:02
  • duplicated? https://stackoverflow.com/questions/9502003/ggplot-scale-y-log10-issue – bbiasi Apr 24 '19 at 02:05
  • The question @bbiasi linked to has a great explanation of why a bar plot and log scale don't work well together – eipi10 Apr 24 '19 at 05:05
  • When you say it reads the log10 numbers do your mean the 10^1, 10^2 notation instead of 1E+01, 1E+02? I've found using `aes(x =x, y = log10(y))` in the mapping with `scale_y_continuous(labels = scales::math_format())` do the 10^1, 10^2 style – teunbrand Apr 24 '19 at 05:47
  • @epipi10 perfect thanks alot! – c_dev Apr 24 '19 at 09:17

0 Answers0