1

I would like to plot a mean difference between two populations of cells, which is very significative (p<0.001). However the scale used is not suitable to see this difference. Here is my code:

ggplot(sh2_sum, aes(treatment,diameter,fill=treatment)) +
    geom_bar(colour='black', width=.7, position=position_dodge(), 
             stat='identity',size=.2) +
    coord_cartesian(ylim=c(0, .4)) +   
    xlab("") + ylab("Diámetro de la cabeza de la espina (µm)") +
    scale_fill_manual(values=c("#009900", "#990000"),name='') +
    geom_errorbar(aes(ymin=diameter, ymax=diameter+se),width=.3,
                  size=.2,position=position_dodge(.7)) +
    theme(legend.direction='horizontal',legend.position=c(.5325,-.085),
          plot.margin=unit(c(0,1,1,1),'cm'), axis.text.x = element_blank()) +
    annotate("text", x=2, y=.355, label="* * *")

This is the graph I get:

original graph

I have tried to use scale_y_log10()but I get the following error:

Error in seq.default(min, max, by = by) : 'from' must be a finite number In addition: Warning message: Transformation introduced infinite values in continuous y-axis

I would like to use a type of scale_y_sqrt in such a way that values from 0 to 3 are short and then values from 3 to 4 are large, so the difference would be visible Any ideas?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • I think you should consider just zooming in to the area you are interested in with `coord_cartesian`, or dropping `geom_bar` altogether in favour of `geom_pointrange`, rather than introducing an arbitrary scale transformation – Mikko Marttila Oct 28 '17 at 13:16
  • Square roots and logs will magnify differences when `y` is small and compress values when `y` is bigger. Warp your data so that it looks like the relative differences are bigger than they really are, you'll want some sort of exponential transformation, maybe `exp(y)` or `y^2`. Or, less deceptively, go with Mikko's suggestion - a line plot or scatterplot isn't expected to start at 0 so you can focus more on the difference than on the absolute magnitudes. – Gregor Thomas Oct 28 '17 at 13:22

1 Answers1

4

A log-transformed y-axis never makes sense for a bar chart, because bars always start at 0, and log(0) isn’t a useful value (hence the error message).

You can use other, zero-differentiable transformations (e.g. asinh) but a vastly easier, and also more meaningful, solution would be to ditch bar charts and use a boxplot (geom_boxplot) instead.

In fact, what you have is called a “dynamite plot” and it’s a classical visualisation anti-pattern.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214