Question: RNA-seq coverage plots via ggplot --> Error in as.vector(x, "character") : cannot coerce type 'environment' to vector of type 'character'
0
gravatar for canberkyurek
3.4 years ago by
canberkyurek0 wrote:

Hi there! I am very new in this field and learning bit by bit. really appreciate your help! I am trying to normalize a set of RNA-seq data chromsome by chromsome in my case. Before normalisation, I just want to plot coverage on individual chromosomes. Here is my code from bioconductor:

>library(GenomicAlignments)
>library(Rsamtools)
>library(ggplot2)

>elution_wt1 <- "/Users/berkyurekahmetcan/Dropbox (ericmiskalab)/cambridge-UK/NGS/piChIP/smallRNA/elution/wt1/elution_wt1_22Gs_dedup.bam"

## Coverage of a GAlignments object:

>elution_wt1_gal <- readGAlignments(elution_wt1)
>elution_wt1_cvg <- coverage(elution_wt1_gal)
>elution_wt1_cvg

>elution_wt2 <- "/Users/berkyurekahmetcan/Dropbox (ericmiskalab)/cambridge-UK/NGS/piChIP/smallRNA/elution/wt2/elution_wt2_22Gs_dedup.bam"


## Coverage of a GAlignments object:

>elution_wt2_gal <- readGAlignments(elution_wt1)
>elution_wt2_cvg <- coverage(elution_wt1_gal)
>elution_wt2_cvg

>elution_wt3 <- "/Users/berkyurekahmetcan/Dropbox (ericmiskalab)/cambridge-UK/NGS/piChIP/smallRNA/elution/wt3/elution_wt3_22Gs_dedup.bam"


## Coverage of a GAlignments object:

>elution_wt3_gal <- readGAlignments(elution_wt1)
>elution_wt3_cvg <- coverage(elution_wt1_gal)
>elution_wt3_cvg

>vctr1 <- as.vector(elution_wt1_cvg[[8]])
>vctr2 <- as.vector(elution_wt2_cvg[[8]])
>vctr3 <- as.vector(elution_wt3_cvg[[8]])

#[[8]] corresponds to the piRNAsensor, which is an extrachromosomal addition!

>wt1 = as.data.frame(vctr1)
>wt2 = as.data.frame(vctr2)
>wt3 = as.data.frame(vctr3)

>x = 1:1663
>y = wt1[,1]
>coverage = data.frame(x,y)
>p = ggplot(coverage) + aes(color = "red") + labs(title = 'elution_wt1', x = 'bps (piRNAsensor)', y = 'Coverage') + scale_x_continuous(scale_fill_grey(start = 1, end = 1663, na.value = "red")) + scale_y_continuous(limits=c(0, 10)) 
>ggsave("wt1.pdf",p)

When I run this script, I get an error as:

> source('~/Dropbox (ericmiskalab)/cambridge-UK/NGS/piChIP/smallRNA/coverage.R')
> p
Error in as.vector(x, "character") : 
  cannot coerce type 'environment' to vector of type 'character'

I would really appreciate your help in this case. Is there any problem with my code? How can I resolve this issue?

sequencing rna-seq • 1.4k views
ADD COMMENTlink modified 3.4 years ago • written 3.4 years ago by canberkyurek0

You're not actually starting the lines with > in coverage.R, I hope.

ADD REPLYlink written 3.4 years ago by Devon Ryan98k

of course not :). I was just trying to find the best way to write the code in this platform.

ADD REPLYlink written 3.4 years ago by canberkyurek0
0
gravatar for canberkyurek
3.4 years ago by
canberkyurek0 wrote:

I think I found the solution by myself. "aes" must be specificed within ggplot!

p = ggplot(coverage, aes(x=x, y=y)) + labs(title = 'elution_wt1', x = 'bps (piRNAsensor)', y = 'Coverage') + scale_x_continuous(scale_fill_grey(start = 1, end = 1663, na.value = "red")) + scale_y_continuous(limits=c(0, 10))

ggsave("wt1.pdf",p)

ADD COMMENTlink written 3.4 years ago by canberkyurek0
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: 2649 users visited in the last hour
_