Question

I tried googling and searching through forums to see if someone had the same issue, but I couldn't find anyone with a problem like this one. It's possible that it is because I am overlooking something completely obvious, but after spending entirely too much time on this, I thought I might ask here.

Essentially, I have a large table (Large_table) that looks like this:

    nam startpos endpos  means File.Name
  12142 Chr 2        1  10000 0.1032  Strain_164
  12143 Chr 2    10001  20000 0.0097  Strain_164
  12144 Chr 2    20001  30000 0.0000  Strain_164
  12145 Chr 2    30001  40000 0.0000  Strain_164
  12146 Chr 2    40001  50000 0.0000  Strain_164
  12147 Chr 2    50001  60000 0.0000  Strain_164
  ...
  ...
  ...
  3240 Chr X 32390001 32400000 1.1921 Strain_98
  3241 Chr X 32400001 32410000 0.0827 Strain_98
  3242 Chr X 32410001 32420000 2.5432 Strain_98
  3243 Chr X 32420001 32430000 0.0404 Strain_98
  3244 Chr X 32430001 32440000 0.2218 Strain_98
  3245 Chr X 32440001 32450000 0.0645 Strain_98

What I have been trying to do is make a set of plots using ggplot and the facet_wrap option. The code for it is the following:

p <- ggplot(data = Large_table, aes(x=startpos, y=means)) 
       + geom_point(aes(colour=nam), size = 2) 
       + coord_cartesian(ylim = c(0, 30)) + xlab("Chromosome Position (Mb)") 
       + ylab("Average Coverage per 10kb")
p <- p + theme(legend.position="none") 
       + scale_x_continuous(labels=function(x)x/1000000) 
       + ggtitle(y) + facet_grid(File.Name ~ nam , margins = T, scales="free_x", drop=T)
p <- p + theme(panel.background = element_rect(fill="white"), panel.margin=unit(1,"lines"))

I end up with a plot that looks like this:

Example of plots produced by ggplot

My issue is that I don't want the (all) column and row. I want only my data plotted, not the pooled results, and I don't know why ggplot is even making that. I looked at the help file but had no luck finding anything there either. I apologize again in advance because to me this seems like a really stupid question, but I cannot figure out why this is happening.

Thank you

Was it helpful?

Solution

If you don't want to get margins, set margins = F within facet_grid()

with in your case will be

facet_grid(File.Name ~ nam , margins = F, scales = "free_x", drop = T)

for more on faceting: ?facet_grid, at docs.ggplot2, R Cookbook

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top