0

In order to better visualize my data, I want to apply scale_y_sqrt() function.

Without this function, the right number of sequences is associate, with 3 000 000 for the highest bar:

enter image description here

ggplot(nb_sequences,aes(x=ordre,y=count,fill=plante)) + geom_bar(stat='identity', width=0.6) + theme(
  axis.text.x = element_blank(), plot.margin = unit(c(0, 0.5, 0, 3.7), "cm")) +
  scale_fill_manual(values=c("#9F7CFC","#80b1d3","#fdb462","#b3de69","#ff4f4f")) + 
  theme(legend.position="left") +
  guides(fill=guide_legend(title="Plant")) +
  xlab('') +
  ylab('Number of sequences') + scale_y_continuous(labels = scales::comma) 

But when I apply the function, the number change to 10,000,000 in the wrong way:

enter image description here

ggplot(nb_sequences,aes(x=ordre,y=count,fill=plante)) + geom_bar(stat='identity', width=0.6) + theme(
  axis.text.x = element_blank(), plot.margin = unit(c(0, 0.5, 0, 3.7), "cm")) +
  scale_fill_manual(values=c("#9F7CFC","#80b1d3","#fdb462","#b3de69","#ff4f4f")) + 
  theme(legend.position="left") +
  guides(fill=guide_legend(title="Plant")) +
  xlab('') +
  ylab('Number of sequences') + scale_y_sqrt(labels = scales::comma) 

How could I fix it ?

Vincent Darbot
  • 217
  • 3
  • 11
  • Please provide a minimal reproducible example. – Christoph Apr 27 '20 at 16:06
  • 1
    It doesn't make sense to do a square root transform on stacked data. It transforms every piece, then stacks. So if your data is 9 and 16, it'll be transformed to 3 and 4, stacked to max out at 7, which is not the same as `sqrt(9+16) == 5`. – teunbrand Apr 27 '20 at 16:07
  • 1
    Similar issue as this question: https://stackoverflow.com/questions/9502003/ggplot-scale-y-log10-issue – Dave2e Apr 27 '20 at 16:17

0 Answers0