0

I have a load of genomic data as follows

chr   leftPos    V
1      1232      122
1      3232      443
1      43534     13  
3      12        12
3      234234    432
4      1222      155
5      4324      124
5      345345    75
5      456457    83

I would like to plot this data as a barplot organised by chr so that all the bars for chr1 are shown then chr2 etc exactly as per the dataframe

All I've managed so far is:

ggplot(TBB_2)+
  geom_bar(aes(TBB_2$leftPos, TBB_2$V),stat="identity", fill="red",group="chr")

but I get the error

Warning messages:
1: Stacking not well defined when ymin != 0 
2: position_stack requires constant width: output may be incorrect 

EDIT

So I tried an alternative method which is to organise as a facet plot so that each facet represents a chr, but nothing is being plotted and I don't know why not:

ggplot(TBB_2)+
  geom_bar(aes(x = TBB_2$leftPos,y = as.numeric(TBB_2$V)),stat="identity")+
  facet_wrap(~ chr)

enter image description here

Sebastian Zeki
  • 6,690
  • 11
  • 60
  • 125
  • Looking at your question again, I'm not sure what you're looking for. What is `leftPos` for, if the position on the x-axis is determined by `chr`? – Frank Nov 13 '15 at 23:27
  • It is not clear to me what kind of plot you want to achieve with this data. – SabDeM Nov 13 '15 at 23:27
  • The idea was to have leftPos by chr. So in other words V would be plotted for the whole length of each chromosome (=chr). I guess another way to do it is as a facet plot for each chromosome but I'm having problems with this as per my edit just now – Sebastian Zeki Nov 13 '15 at 23:29
  • What do you mean by `V would be plotted for the whole length of each chromosome (=chr)`. What determines the height of the bars? `V` or `leftPos` – DatamineR Nov 13 '15 at 23:41

1 Answers1

2

Would that work for you?

ggplot(TBB_2, aes(x=factor(leftPos), y=V)) +
  facet_grid(. ~ chr, scales="free_x", space="free_x") +
  geom_bar(stat="identity")

(Note that you need leftPos treated as factor, and set free scaling and spacing on x axis)

R plot

Hope that helps!