-3

I am trying to plot the gene expression of "gene A" among several groups. I use ggplot2 to draw, but I fail

p <- ggplot(MAPK_plot, aes(x = group, y = gene_A)) + geom_violin(trim = FALSE , aes( colour = gene_A))  + theme_classic()

And I want to get the figure like this from https://www.researchgate.net/publication/313728883_Neuropilin-1_Is_Expressed_on_Lymphoid_Tissue_Residing_LTi-like_Group_3_Innate_Lymphoid_Cells_and_Associated_with_Ectopic_Lymphoid_Aggregates

Joe
  • 8,073
  • 1
  • 52
  • 58
  • 3
    Hello [陈海填](https://stackoverflow.com/users/8729894/陈海填), welcome to SO. Please take a look at [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), to modify your question, with a smaller sample taken from your data (check?dput()). Posting images of your data or no data makes it difficult to impossible for us to help you! – massisenergy Dec 23 '18 at 09:20

1 Answers1

0

You would have to provide data to get a more specific answer, tailored to your problem. But, I do not want that you get demotivated by the down-votes you got so far and, based on your link, maybe this example can give you some food for thought.

Nice job on figuring out that you have to use geom_violin. Further, you will need some form of faceting / multi-panels. Finally, to do the full annotation like in the given link, you need to make use of the grid package functionality (which I do not use here).

I am not familiar with gene-expression data sets, but I use a IMDB movie rating data set for this example (stored in the package ggplot2movies).

library(ggplot2)

library(ggplot2movies)
library(data.table)
mv <- copy(movies)
setDT(mv)
# make some variables for our plotting example
mv[, year_10 := cut_width(year, 10)]
mv[, rating_10yr_avg := mean(rating), by = year_10]
mv[, length_3gr := cut_number(length, 3)]

ggplot(mv, 
       aes(x = year_10, 
           y = rating)) + 
  geom_violin(aes(fill = rating_10yr_avg),
              scale = "width") +
  facet_grid(rows = vars(length_3gr))

enter image description here

Please do not take this answer as a form on encouragement of not posting data relevant to your problem.

Valentin_Ștefan
  • 6,130
  • 2
  • 45
  • 68