showteeth / ggcoverage

Visualize and annotate genomic coverage with ggplot2

Home Page:https://showteeth.github.io/ggcoverage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unable to plot a basic coverage?

takahyoro opened this issue · comments

I could not plot a basic coverage from my .bw files converted from .bam by deeptools.
I wonder whether I misunderstood what the manual says.

Error in UseMethod("group_by") : no applicable method for 'group_by' applied to an object of class "NULL" `

The full code run follows:
library("rtracklayer")
library("graphics")
library("ggcoverage")

bw <- c("/data1.bam.bw", "/data2.bam.bw")
meta<- data.frame(SampleName=c("data1.bam", "data2.bam"),
Type=c("type1","type2"),
Group=c("group1", "group2"))
track.df <- LoadTrackFile(bw,
meta.info = meta,
format ="bw")
ggcoverage(data = track.df)

---environment---
R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"
Platform: x86_64-apple-darwin17.0 (64-bit)

Hi,
Can you provide the track.df you loaded? And ggcoverage have some presented parameters, such as region = "chr14:21,677,306-21,737,601", gene.name = "HNRNPC", this is full help information of ggcoverage.

Thank you for your kindness.

The track.df file was attatched.
And I am reading the full help information carefully.

221122_track_df.txt

If you do not need to add annotation, you can use the geom_coverage which is designed to visualize coverage plot. And ggcoverage requires gtf to extract region.

library(ggplot2)
test = read.table('./221122_track_df.txt', header = T)
ggplot() +
  geom_coverage(data = test, color = "auto", mark.region = NULL) +
  theme_coverage()

image

Let me know if that helps or if you have any other questions.

YB

Thank you very much for your suggestion.

The script you provided with a little modification worked well, although color = "auto" and theme_coverage() did not work (I haven't known why).
Anyway, I finally got the plot I intended. Again thank you very much.

Glad to hear that!
But, what do you mean

color = "auto" and theme_coverage() did not work (I haven't known why).

Can you explain this in detail, such as the codes you used and the results you want.

The codes and following results are shown below.

<code#1>
library(ggplot2)
test <- read.table('./221122_track_df.txt', header = T)
ggplot() +
geom_coverage(data = test, color = "auto", mark.region = NULL) +
theme_coverage()
<result#1>
Error in coord_cartesian(xlim = x.range) :
argument "x.range" is missing, with no default
In addition: Warning message:
In geom_coverage(data = test, color = "auto", mark.region = NULL) :
The color you provided is not as long as Type column in data, select automatically!

<code#2>
library(ggplot2)
test <- read.table('./221122_track_df.txt', header = T)
ggplot() +
geom_coverage(data = test, mark.region = NULL) +
theme_coverage()
<result#2>
Error in coord_cartesian(xlim = x.range) :
argument "x.range" is missing, with no default

I see, this error occurs when the version of ggcoverage you used is below 0.8.0!

You can update ggcoverage with following codes:

# install via Github
# install.package("remotes")   #In case you have not installed it.
remotes::install_github("showteeth/ggcoverage")