Question: Plot On Both Sides Of Axis
0
gravatar for raj.karthik437
6.3 years ago by
raj.karthik43740 wrote:

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 • 4.8k views
ADD COMMENTlink modified 6.3 years ago by Woa2.8k • written 6.3 years ago by raj.karthik43740
4

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 REPLYlink written 6.3 years ago by David W4.7k

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 REPLYlink written 6.3 years ago by raj.karthik43740

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 REPLYlink modified 6.3 years ago • written 6.3 years ago by David W4.7k
1

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

A: Multiple histograms in one plot

ADD REPLYlink modified 6 months ago by RamRS27k • written 6.3 years ago by Woa2.8k
1
gravatar for ancient_learner
6.3 years ago by
India
ancient_learner630 wrote:

check this out: http://stackoverflow.com/questions/6999144/how-do-you-create-a-bar-plot-for-two-variables-mirrored-across-the-x-axis-in-r

ADD COMMENTlink written 6.3 years ago by ancient_learner630
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1291 users visited in the last hour