0

data I am trying to log transform the axis on the bottom of the graph, but I think coord_flip() is somehow inhibiting this. I've tried using scale_y_continuous(trans = "log10"), coord_trans(y = "log10") and scale_y_log10(). None of these worked to log transform that axis. This is the code with no transformation and the output.

data set in excel dput(df) Plot with no transformation

Plot with no transformation

Any help is much appreciated!

p1 <-ggplot(data = df,
       aes(x = Quintile, y = OR, ymin = Lower, ymax = Upper))+
  geom_pointrange(aes(col = Quintile))+
  geom_hline(aes(fill = Quintile), yintercept = 1, linetype = 2)+
  labs(x = "Treatment",  y = "OR and 95% CI")+
  geom_errorbar(aes(ymin = Lower, ymax = Upper, col = Quintile), width = 0.5)+
  facet_wrap(~TX, strip.position = "left", nrow = 5,scales = "free_y")+
  theme_classic()+
  theme(plot.title = element_text(size = 16, face = "bold"),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.x = element_text(face = "bold"),
        axis.title = element_text(size = 12, face = "bold"),
        strip.text.y = element_text(hjust = 0,vjust = 1,angle = 180, face = "bold"),
        legend.position = "NULL")+
  coord_flip()
p1
Heather
  • 1
  • 1
  • 2
    Hi Heather, could you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) in your question? By doing so, other can reproduce the error and try to address it. Using `scale_y_log10()` followed by `coord_flip()` should keep the log scale. – Bushidov Sep 22 '22 at 04:32
  • 1
    Can you post sample data? Please edit the question with the output of `dput(df)`. Or, if it is too big with the output of `dput(head(df, 20))`. – Rui Barradas Sep 22 '22 at 05:00
  • Most ggplot geoms work fine since v3.3.0 in 2020 with the x/y specified in the order you want them, so most (all?) uses of coord_flip can be avoided. https://www.tidyverse.org/blog/2020/03/ggplot2-3-3-0/#bi-directional-geoms-and-stats – Jon Spring Sep 22 '22 at 05:54
  • @RuiBarradas I added in the data set. I don't know how to make the plot without coord_flip. Everything I've tried without it looks really strange. Thank you all for your help. – Heather Sep 23 '22 at 05:13

0 Answers0