質問

In the data that I am attempting to plot, each sample belongs in one of several groups, that will be plotted on their own grids. I am plotting stacked bar plots for each sample that will be ordered in increasing number of sequences, which is an id attribute of each sample.

Currently, the plot (with some random data) looks like this: (Since I don't have the required 10 rep for images, I am linking it here) http://i.stack.imgur.com/A9hr2.png

There are couple things I need to accomplish. And I don't know where to start.

  1. I would like the bars not to be placed at its corresponding nseqs value, rather placed next to each other in ascending nseqs order.
  2. I don't want each grid to have the same scale. Everything needs to fit snugly.

I have tried to set scales and size to for facet_grid to free_x, but this results in an unused argument error. I think this is related to the fact that I have not been able to get the scales library loaded properly (it keeps saying not available).

Code that deals with plotting:

ggfdata <- melt(fdata, id.var=c('group','nseqs','sample'))
p <- ggplot(ggfdata, aes(x=nseqs, y=value, fill = variable)) + 
       geom_bar(stat='identity') + 
       facet_grid(~group) + 
       scale_y_continuous() + 
       opts(title=paste('Taxonomic Distribution - grouped by',colnames(meta.frame)[i]))
役に立ちましたか?

解決

Try this:

update.packages()
## I'm assuming your ggplot2 is out of date because you use opts()
## If the scales library is unavailable, you might need to update R

ggfdata <- melt(fdata, id.var=c('group','nseqs','sample'))
ggfdata$nseqs <- factor(ggfdata$nseqs)
## Making nseqs a factor will stop ggplot from treating it as a numeric,
## which sounds like what you want

p <- ggplot(ggfdata, aes(x=nseqs, y=value, fill = variable)) + 
    geom_bar(stat='identity') + 
    facet_wrap(~group, scales="free_x") + ## No need for facet_grid with only one variable
    labs(title = paste('Taxonomic Distribution - grouped by',colnames(meta.frame)[i]))
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top