1

In the following example data frame, I would like to have 2 segments y-axis (break in the y-axis) for better resolution in visualisation of smaller values in "lna1". I have already tried facet_wrap but I would like to use facet_grid for comparison of genes with same y-scale.

df<-data.frame(stimulation=rep(rep(c("a","b","c"), each=3),2),
           LNA=rep(c("lna1","lna2"),each=9), 
           foldchange=c(5,6,7,10,11,12,4,3,2,40,45,55,7,8,10,99,100,101))
n <- 3  
df<-do.call("rbind", replicate(n, df, simplify = FALSE))%>%
  mutate(genes=rep(c("gene1","gene2","gene3"), each=18))



ggplot(df, aes(x=LNA, y=foldchange,fill = stimulation))+
  geom_point() +
  geom_boxplot(alpha = 0.2) +
  theme(axis.text.x = element_text(angle = 60, hjust = 1)
        ,legend.background = element_rect(fill = "white", colour = NA)) +
  geom_hline(yintercept = 1) +
  scale_x_discrete(limits=c("lna1","lna2")) +
  facet_grid(stimulation~genes, scales="free")

Plot

aosmith
  • 34,856
  • 9
  • 84
  • 118
  • There is not a way to create a broken axis in ggplot2. See [this thread](https://stackoverflow.com/questions/7194688/using-ggplot2-can-i-insert-a-break-in-the-axis) for a discussion of other possible solutions (packages which can do broken axes, and alternate ways of displaying this type of data if you want to stay in ggplot2) – Jan Boyer Aug 08 '17 at 18:14
  • Thanks Jan. Although I don't like but I have to plot log2 values. – Sajjad khani Aug 09 '17 at 12:22
  • Possible duplicate of [Using ggplot2, can I insert a break in the axis?](https://stackoverflow.com/questions/7194688/using-ggplot2-can-i-insert-a-break-in-the-axis) – Jan Boyer Oct 20 '17 at 17:16
  • Seems that it is not possible and I plotted log2 transformed values. – Sajjad khani Oct 23 '17 at 15:24

0 Answers0