well yes data tidying up is something i m learning before I can go to ggplot and make graphs.
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
1 answer
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()
Log in to answer this question.
Also post the code you tried. It would be easy to debug.
What is the plot type (density, plot, line ...) are you trying with ggplot ?