Thank you! it's work but there is the probleme of resolution i can't differentiate between boxplots
i need a method without ggplot
Hello,
I have a table fpkm (20 tissues)
gene_id category tissue1 tissue2 tissue3 tissue4 …... tissue20 g1 unkown g2 Known g3 Known g4 unkown . . . . g3000
[url=https://postimg.org/image/4nvn96jdn/][img]https://s9.postimg.org/757egg3a7/Screen_Shot_2016_09_14_at_12_10_11_PM.png[/img][/url][url=https://postimage.org/]photo uploading[/url]
I would like to make boxplot (in the same figure) of expression in two categories across all tissues
like in the picture
Thank you
[url=https://postimg.org/image/5l3cmfqjx/][img]https://s22.postimg.org/5l3cmfqjx/Picture1.png[/img][/url]
There is an example of that kind of plot at http://docs.ggplot2.org/current/geom_boxplot.html You'd need to manipulate your matrix from wide (as you've given at postimg.org) to long format before using the code there:
library(reshape) # wide to long
library(ggplot2) # boxplots
library(magrittr) # %>%
set.seed(1) #
# simplified version of your data.frame
dfr.wide <- data.frame(
gene.id = as.character(1:10),
category = sample(c('known', 'unknown'), size = 10, replace = TRUE),
tissue.1 = rnorm(10),
tissue.2 = rnorm(10),
tissue.3 = rnorm(10),
tissue.4 = rnorm(10)
)
dfr.wide %>% head
gene.id category tissue.1 tissue.2 tissue.3 tissue.4
1 1 known -0.8204684 -0.04493361 -0.05612874 -0.4149946
2 2 known 0.4874291 -0.01619026 -0.15579551 -0.3942900
3 3 unknown 0.7383247 0.94383621 -1.47075238 -0.0593134
4 4 unknown 0.5757814 0.82122120 -0.47815006 1.1000254
5 5 known -0.3053884 0.59390132 0.41794156 0.7631757
6 6 unknown 1.5117812 0.91897737 1.35867955 -0.1645236
# want:
# tissue category gene expression
# tissue.1 unknown '1' 1.90 ...
# .
# .
dfr.long <- melt(
dfr.wide,
id = c('gene.id', 'category'),
variable_name = 'tissue'
)
dfr.long %>% head
gene.id category tissue value
1 1 known tissue.1 -0.8204684
2 2 known tissue.1 0.4874291
3 3 unknown tissue.1 0.7383247
4 4 unknown tissue.1 0.5757814
5 5 known tissue.1 -0.3053884
6 6 unknown tissue.1 1.5117812
# plot it:
ggplot(
data = dfr.long,
aes(x = tissue, y = value)
) + geom_boxplot(aes(col = category))
End:
Plotting code:
Thank you! it's work but there is the probleme of resolution i can't differentiate between boxplots
i need a method without ggplot
I'd suggest you experiment with ggplot for a while before you disregard it: play with the aesthetics/themes, reduce your dataset etc. The problem may be one of design rather than implementation
I second ggplots and look at violin plots within it link to geom_violin plots and you can colour by some factor or group.
You can then use the facet function to further subclassify your groups. Link to facet grid
You can certainly use par(mfrow=c(x,y)) where x= rows and y=columns. Run the box plots the x*y array and finally set it to par(mfrow=c(1,1)). par(mfrow(x,y)) divides the graph board in to x columns and Y rows.
You can reset the graphical setting with a single dev.off() command
Take a look to this ggplot2 tutorial that includes the code you can reuse for your own data Don't forget to revise the Aesthetics section to change the aspect of your graphics
Log in to answer this question.
You can certainly use par(mfrow=c(x,y)) where x= rows and y=columns. Run the box plots the x*y array and finally set it to par(mfrow=c(1,1)). par(mfrow(x,y)) divides the graph board in to x columns and Y rows.