Entering edit mode
13 months ago
Assa Yeroslaviz
★
1.9k
Good morning, I am trying to recreate for my data an image I saw in a journal, as I find it very intuitive. The image is attached below.
For my data I have for each GO category a list of named vectors containing the log2-FC values for each of the genes, but I also have the data as a data.frame
.
List of 10
$ GO1 : Named num [1:104] -0.938 -0.874 1.044 1.209 -1.019 ...
..- attr(*, "names")= chr [1:104] "SFRP2" "COL4A1" "NRCAM" "PTGIS" ...
$ GO2 : Named num [1:69] -1.701 -1.622 1.892 -1.189 0.807 ...
..- attr(*, "names")= chr [1:69] "APOE" "GUCY1A1" "HSPB7" "GUCY1B1" ...
I'm just not sure, how to plot the bars for each of the vectors using ggplot
. I think, one can do this with a barplot of height 1
by adding another column? But this seems to be just a workaround and not the best solutions.
I would happy to hear of other, more to the point solutions.
thanks
Assa
I think you can start with geom_tile, for example this code can help you to create the general shape of your plot and then you can customize and then arrange individual plots (maybe with ggarrange ?) :
thanks Basti for the suggestions. I sort of have now a good start, but this is still not exactly good enough
this is
ggplot
commandand the image resulting from this is also attached at the bottom.
I would like to know if there is a possibility to for each of the facets a fixed width for each gene. For now, the width of the last facet with only two genes is exactly the same as the one with over 100 genes. Is it possible to set a fixed width for the facets?
thanks again
From what I have quickly found on Stack Overflow, one way could be to use egg::set_panel_size to fix the width of the geom_tile (https://stackoverflow.com/questions/20638294/geom-tile-and-facet-grid-facet-wrap-for-same-height-of-tiles)
Actually this is the result if I do it manually for two plots, I think you can adapt with for loop or apply to make the code clearer :
cool, the egg package looks really good. I'll give it a try. thanks