0

I am hoping to set up a box and whisker plot with log(ORs). On a linear scale, I am able to specify my breaks/ticks at 0.5, 1, 2, 4, but when I log-transform my y-axis, tick marks only appear at 1 and 2. I know I am missing something trivial, and am open to the fact that I am missing something very simple. I've tried looking through about 20 StackOverflow pages including someone who described a similar problem for javascript. Any help wuould be appreciated!

This will yield a linear plot with the breaks I want (but not log transformed)

plot <- ggplot(data=df,
    aes(x = group, y = riskratio))+
    geom_point(shape=22, fill="black", size=5)+
    scale_y_continuous(trans = 'log10', breaks = c(0.5, 1, 2) )+ 
    geom_hline(aes(fill=group),yintercept =1, linetype=2)+
    xlab('score\n(quintiles)')+ ylab("Multivariable odds ratio\n(95% confidence interval) \n")+
    geom_errorbar(aes(ymin=lowerlimit, ymax=upperlimit,col=group),width=0.2,cex=1, color = 'gray50')+ 
    facet_wrap(~condition,strip.position="top",nrow=1,scales = "free_x") +
    guides(color = "none") +
    geom_smooth(alpha=0.3, method = "lm", se=TRUE, aes(group=1), color='gray50', linetype=0) +
    theme_bw(base_size = 24) +
    theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + 
    annotate(geom = "text", label = c('p-trend=0.003', 'p-trend=0.004', 'p-trend=0.27'), size = 7, hjust = .1, x='Q1 (ref.)', y =2.3)
plot(plot)

This will yield a log transformed plot but without the breaks I want (just 1 and 2)

plot <- ggplot(data=df,
    aes(x = group, y = riskratio))+
    geom_point(shape=22, fill="black", size=5)+
    scale_y_continuous(trans = 'log10', breaks = c(0.5, 1, 2) )+ 
    geom_hline(aes(fill=group),yintercept =1, linetype=2)+
    xlab('score\n(quintiles)')+ ylab("Multivariable odds ratio\n(95% confidence interval) \n")+
    geom_errorbar(aes(ymin=lowerlimit, ymax=upperlimit,col=group),width=0.2,cex=1, color = 'gray50')+ 
    facet_wrap(~condition,strip.position="top",nrow=1,scales = "free_x") +
    guides(color = "none") +
    geom_smooth(alpha=0.3, method = "lm", se=TRUE, aes(group=1), color='gray50', linetype=0) +
    theme_bw(base_size = 24) +
    theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + 
    annotate(geom = "text", label = c('p-trend=0.003', 'p-trend=0.004', 'p-trend=0.27'), size = 7, hjust = .1, x='Q1 (ref.)', y =2.3)
plot(plot)
Long
  • 11
  • 2
  • 1
    I suspect the break of 0.5 is outside the range of "your plotted data plus the default 5% expansion." You could use coord_cartesian to specify the y range you want, or something like `expand = expand_scale(mult = 1)` inside your `scale_y_continuous` line. – Jon Spring May 29 '19 at 01:23
  • 1
    Quite possible, though hard to tell without a reproducible example... @Long, here are some suggestions on how to do that, it really does help a lot in helping us help you. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Aaron left Stack Overflow May 29 '19 at 02:53

0 Answers0