0

I want to plot CNV using CNV-seq output, but I found that chromosome names are on the top of the picture, how could I move the chromosome names to the bottom. Here is my code used to plot CNV:

data = read.table('/Users/andy/Desktop/plot_R/17A020980.sorted.cnr', head=T, sep='\t', check.names = F)
data$chromosome = factor(data$chromosome, levels=c(paste0('chr', 1:22), 'chrX', 'chrY'))
p = ggplot(data, aes(start, 2*2^data$log2, color=chromosome)) +geom_point()+scale_x_discrete(breaks=NULL)+theme_minimal()+theme(legend.position="none")+xlab(NULL)+facet_grid(.~chromosome, scale="free"))
p + scale_y_continuous(name="Copy Number", limits = c(0,8))

And the result is shown in this picture

Robert
  • 7,394
  • 40
  • 45
  • 64
  • Does this answer your question? [can I change the position of the strip label in ggplot from the top to the bottom?](https://stackoverflow.com/questions/3261597/can-i-change-the-position-of-the-strip-label-in-ggplot-from-the-top-to-the-botto) – stefan Mar 22 '20 at 10:46
  • @stefan : Yes, it works for me, I appreciate your help very much!!!! – GuoFeng Wang Mar 22 '20 at 10:54
  • GuoFeng, can you add a dput of your data? It will help to reproduce what you have in the image – user5249203 Oct 27 '22 at 12:57

1 Answers1

0

Using switch = "x" in facet_wrap() or facet_grid. Try this:

ggplot(mtcars, aes(hp, mpg)) +
  geom_point() +
  facet_grid(.~cyl, switch = "x")
stefan
  • 90,330
  • 6
  • 25
  • 51