ggplot for expression data
1
2
Entering edit mode
7.3 years ago
1769mkc ★ 1.2k

My expression data frame pretty small subset of it is as such

  gene                    value_1                   value_2
XLOC_000060           3.662330                   0.3350140
XLOC_000074           2.568130                   0.0426299

I been struggling with ggplot how to trasform the data so that I can plot it in ggplot i basically how do I define the factor etc.

saw few examples but I guess im still not able to replicate what they did with the sample data

I end up getting this error Error in eval(expr, envir, enclos) its a pretty fundamental error I suppose which I fail to figure out..

Any help would be highly appreciated

R • 6.9k views
ADD COMMENT
1
Entering edit mode

What is the plot type (density, plot, line ...) are you trying with ggplot ?

ADD REPLY
0
Entering edit mode

Also post the code you tried. It would be easy to debug.

ADD REPLY
9
Entering edit mode
7.3 years ago
ddiez ★ 2.0k

You have to tidy your data to plot it effectively with ggplot2. There are many ways to do this, below I show two (assuming you want to plot a heatmap). Note the difference in data rearrangement between d and dd. Also, highly recommend reading the tidyr vignette and the Tidy data section in the book "R for data science" by Hadley Wickham (creator of ggplot2, tidyr and reshape2). The online version of this book is available here.

# create sample (untidy) dataset.
d <- read.table(header = TRUE, text = 
 "gene                   value_1                     value_2
  XLOC_000060           3.662330                   0.3350140
  XLOC_000074           2.568130                   0.0426299")

d
         gene value_1   value_2
1 XLOC_000060 3.66233 0.3350140
2 XLOC_000074 2.56813 0.0426299

# tidy it using tidyr package.
library(tidyr)
dd <- d %>% gather(sample, value, -gene)
dd
         gene  sample     value
1 XLOC_000060 value_1 3.6623300
2 XLOC_000074 value_1 2.5681300
3 XLOC_000060 value_2 0.3350140
4 XLOC_000074 value_2 0.0426299

# plot heatmap.
ggplot(dd, aes(x = sample, y = gene, fill = value)) + geom_tile()

# tidy it using reshape2 package.
library(reshape2)
dd <- melt(d, variable.name = "sample")
ggplot(dd, aes(x = sample, y = gene, fill = value)) + geom_tile()
ADD COMMENT
0
Entering edit mode

well yes data tidying up is something i m learning before I can go to ggplot and make graphs.

ADD REPLY

Login before adding your answer.

Traffic: 2539 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6