This is a test version of Biostars. For the public version, visit https://www.biostars.org.
RNA-seq coverage plots via ggplot --> Error in as.vector(x, "character") : cannot coerce type 'environment' to vector of type 'character'

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?

rna-seq sequencing

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

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

1 answer

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)

Log in to answer this question.