Question: Plot line graph when counts are not automatically given
1
gravatar for kristina.mahan
9 weeks ago by
kristina.mahan20 wrote:

I want to plot Depth of Coverage values in R. I've extracted all the Coverage values from my VCF and want to plot it. The x-axis would be Depth and the y-axis would be counts. I don't have the counts specified I just have a .txt file with a column of values.

In R:

library(ggplot2)
filename <- "KMM1_raw_variants_DP_values_10102018.txt"
my_data <- read.csv(filename, sep="\t", header=FALSE)
head(my_data)
   V1
1 350
2 432
3 431
4 479
5 469
6 410
  
names(my_data)[1] <- c("Coverage")
  Coverage
1      350
2      432
3      431
4      479
5      469
6      410
  
ggplot(my_data,aes(x=Coverage, y=counts)) + geom_line()
Error in FUN(X[[i]], ...) : object 'counts' not found
  

How do you specify that you want R to count the times each coverage is present so that I can see the Depth of Coverage so I can know what to filter out when using GATK? First graph here: http://mbontrager.org/blog/2016/08/17/Variant-Exploration

Thanks!!

depth ggplot2 R vcf • 214 views
ADD COMMENTlink modified 9 weeks ago by zx87546.1k • written 9 weeks ago by kristina.mahan20
3
gravatar for Friederike
9 weeks ago by
Friederike2.3k
United States
Friederike2.3k wrote:

You don't want a line plot, you want a histogram/density plot where you capture how many times a given number appears in your coverage column.

In your case you could try:

P <- ggplot(my_data, aes(x = Coverage)) + geom_density()
## zooming in
P + coord_cart(xlim = c(0, 250))

## histogram
ggplot(my_data, aes(x = Coverage)) + geom_histogram()
ADD COMMENTlink written 9 weeks ago by Friederike2.3k

When I do that I get this error:

Error: StatBin requires a continuous x variable: the x variable is discrete. Perhaps you want stat="count"?

ADD REPLYlink written 9 weeks ago by kristina.mahan20

are you sure that the entries of my_data$Coverage are numbers? what does str(my_data) return?

ADD REPLYlink written 9 weeks ago by Friederike2.3k

'data.frame': 725952 obs. of 1 variable: $ V1: num 478 569 568 620 609 545 242 240 229 346 ...

ADD REPLYlink written 9 weeks ago by kristina.mahan20
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: 1647 users visited in the last hour