This is a test version of Biostars. For the public version, visit https://www.biostars.org.
ggplot density plot across bed file

Hi I have a bed file that looks like the following:

       V1      V2        V3        V4        V5        V6
1     chr5 114139382 114139383 38.417794 1.417096e-01 0.90
2     chr5 114139397 114139398 38.230517 1.462339e-01 0.90
3    chr12  71048245  71048246 37.166154 1.500587e-01 0.57
4    chr12  71048296  71048297 41.060579 1.216497e-01 0.57

Column V4 is an average fragment size at each genomic position. I would like to create a density plot describing distributions of average fragment size using column V4 but am not sure how to go about it.

Any idea are much appreciated, thanks!

r ggplot density plot bed bedops

2 answers

Replace mpg to your data.frame and cty to V4

library(tidyverse)

mpg  %>% ggplot() + geom_density(aes(x = cty))

No need to load the whole universe:

library(ggplot2)

ggplot(mpg, aes(cty)) + geom_density()

In base R :

plot(density(df$V4))

if df is your dataframe

Log in to answer this question.