This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Plot On Both Sides Of Axis

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

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.

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?

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

1 answer

Log in to answer this question.