This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to create color range for RPKM/FPKM using R?

Hi every body

I want to create a color range for FPKM/RPKM data using R or another software if it possible, but i don't know how to do it.

For better understanding please take a look at the photo.Thanks a lot

Color range for FPKM / RPKM values

rna-seq r graphic ggplot2 gplots

yes i've read this kind of scale_gradient() diagram but as you see in the chart my values are discrete,

please note that i have more than 10000 FPKM/RPKM values which will be show in the diagram,

anyway thanks again,

Err, your FPKM/RPKM values are continuous, that's why you can simply color by value and use a gradient scale, as in that image.

BTW, you probably want to color on log2 level.

yes of course log2, but how !!??

The simplest way would be to just graph log2(RPKM) to begin with. Alternatively, just add that as a column to the dataframe or just perhaps even use something like colour=log2(RPKM) as an argument.

I might suggest using a density plot of values instead. It will be much more informative, I suspect.

What do you want to use the color gradient for, a heatmap?

1 answer

I offer this way if anybody expert in R please develop it

x <- data.frame(FPKM = rnorm(1000))
x$Color <- cut(x$FPKM, 256)
library(gplot)
library(ggplot2)
x$Color2 <- redgreen(256)[as.numeric(x$Color)]
ggplot(x, aes(FPKM,1,fill=Color2))+geom_bar(stat="identity")+coord_flip()
// Or use below after log2
ggplot(y, aes(FPKM,ymin=-1,ymax=1,color=Color))+
geom_linerange()+coord_flip()+theme(legend.position="none")+scale_x_log10()

Is library(gplot) supposed to be library(gplots)? I tried the graph, and it seems like kind of an odd way to represent the data. Also I get the following error when using the code

> ggplot(y, aes(FPKM,ymin=-1,ymax=1,color=Color))+
+ geom_linerange()+coord_flip()+theme(legend.position="none")+scale_x_log10()
Error: ggplot2 doesn't know how to deal with data of class numeric

Did you copy the code exactly? I agree with the previous poster that said a histogram would be much more informative. They are fairly simple to make, just use the hist() function.

hist(x[,1])

Alternatively, you could plot the data as a line or xyplot where the cumulative percent (or actual number) of genes is on the y-axis and RPKM value (log2) is on the x-axis.

Log in to answer this question.