Entering edit mode
                    11.7 years ago
        raj.karthik437
        
    
        ▴
    
    40
    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.
Check out
?facet_gridif you just want them side by side. If you want the "B" features mirrored you'd need provide "negative counts" forstat_bin/geom_hist. Might need to usecutandtableorhist(..., 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
plyrto apply a function to each subset of a dataframe. Something likeddply(trail, .(chr), my_custom_counting_function)where you custom fuction returns a dataframeCheck this post on how to plot densities below and above the X-axis in GGPLOT
A: Multiple histograms in one plot