Plot On Both Sides Of Axis
1
0
Entering edit mode
10.2 years ago

Hi I have a data (trail) like this

    chr        pos       features
    chr1    1232322    a
    chr1    2344433    a
    chr1    5355555    a
    chr1    17555533    b
    chr1    18655535    b
    chr1    19755535    b

I want to make a density plot using R (ggplot2) for the features namely a and b. I want all the "a" features above x-axis and "b" features to be below x-axis. this is what i have tried

ggplot(trail) + geom_histogram(aes(x=pos),binwidth=1000000)

but this plots all above the axis.

r • 6.2k views
ADD COMMENT
4
Entering edit mode

Check out ?facet_grid if you just want them side by side. If you want the "B" features mirrored you'd need provide "negative counts" for stat_bin/geom_hist. Might need to use cut and table or hist(..., plot=FALSE) to get counts for each feature then multiple one subset by negative one.

ADD REPLY
0
Entering edit mode

Hey thanks for the solution. i was able to do it for one chromosome. however i am planning to plot all chromosomes 1-22,X and Y. Is there any way to get the counts for all chromosomes at a time if i give a single file with chromosome and position?

ADD REPLY
0
Entering edit mode

Without knowing exactly what you are doing, uou could use the library plyr to apply a function to each subset of a dataframe. Something like ddply(trail, .(chr), my_custom_counting_function) where you custom fuction returns a dataframe

ADD REPLY
1
Entering edit mode

Check this post on how to plot densities below and above the X-axis in GGPLOT

A: Multiple histograms in one plot

ADD REPLY

Login before adding your answer.

Traffic: 1756 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6