1
votes

I am trying to plot samples and chromosomes as row and columns using facet grid in ggplot. My problem is that each facet is very small given that I have 25 chromosomes and many samples. Is there a way to plot each facet with its actual size and scroll horizontally and vertically across samples and chromosomes ? Here is my code

seg <- read.table("tmp.seg")
head(seg)
    id  chr   start      end test  ref       log2
2 114F chrY 9992443 10038173 2654 3818 -0.03
3 114F chrY 9969577 10015307  460 1286 -0.99
4 114F chrY 9946711  9992441  497 1348 -0.94
5 114F chrY 9923845  9969575  537 1254 -0.73
6 114F chrY 9900979  9946709 1040 2667 -0.86
7 114F chrY 9878113  9923843  700 2021 -1.03

p <- ggplot(seg) + geom_segment(aes(x=seg$start,y=seg$log2,xend=seg$end,yend=seg$log2,color=seg$log2),size=1) +
    facet_grid(id~chr,scales="free_x") + 
      scale_color_gradient(limits=c(-1,1),low="blue", high="red") +
        theme(panel.background=element_rect(fill="white")) + ylim(c(-2,2))

The results looks like this

enter image description here

As you can see, the facet shrink the plot in which all the details inside disappear. I want to know how to make a high resolution plot in which one can scroll horizontally and vertically to see each chromosome at each sample in high details.

Thanks in advance

1
Save it to a file and you can specify whatever dimensions you want. ggsave("my_plot.pdf", plot = p, height = 18, width = 42, units = "in") should be plenty big enough. - Gregor Thomas
@Gregor Thanks for you suggestion, but the problem isn't in the size of the main plot but rather the size of each facet. The facet shrink the data inside each chromosome, so I was thinking of a way to make the resolution and the size of each facet big enough so one can scroll across all the points in each chromosome. Thanks again - user2694433
I'm not sure I understand... if the main plot is bigger, won't the facets be bigger as well? Wouldn't it be impossible to make the facets bigger without making the main plot bigger? - Gregor Thomas

1 Answers

0
votes

Use a facet_wrap wrapping with certain number of columns or rows. For example, facet_grid(id~chr,ncol=4) would break up your chart into a more clearer representation but unfortunately would not make the chart scroll able.