Get the App
SLTechnology News&Howtos  ›  Development  › 

How to draw Bubble Chart with ggplot2 in r language

Shulou Source: shulou.com Published: 2022-06-01 04:58:11 10月03日 Update

This article mainly shows you "r language how to use ggplot2 to draw bubble chart", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "r language how to use ggplot2 to draw bubble chart" this article.

The results of Pathway enrichment are often shown by bubble chart, and the basic code is as follows:

Case data:

> dat ko_id Kegg_pathway Rich_factor Pvalue DEGs1 ko00195 Photosynthesis 3.543363 1.000000e-15 52 ko00196 Photosynthesis-antenna proteins 5.575221 1.500000e-10 63 ko03008 Ribosome biogenesis in eukaryotes 2.464696 4.920000e-06 74 ko00710 Carbon fixation in photosynthetic organisms 2.567654 4.510000e-05 95 ko01200 Carbon metabolism 1.738592 7.350000e-05 116ko03030 DNA replication 2.453097 1.772599e-03 147ko00030 Pentose phosphate pathway 2.397575 1.772599e-03 128ko00860 Porphyrin and chlorophyll metabolism 2.574238 1.772599e-03 149ko00062 Fatty acid elongation 2.857551 2.316650e- 03 1810 ko00630 Glyoxylate and dicarboxylate metabolism 2.129425 5.299956e-03 1911 ko00230 Purine metabolism 1.671398 5.299956e-03 4

The drawing process of bubble diagram is often realized by using geom_point geometric object function, and the coordinate axis is flipped at the same time.

Note that the significant size-log10 (Pvalue) is mapped to the point color, and the number of differential genes is mapped to the point size.

Kegg_point=ggplot (dat,aes) + geom_point (aes (color=-log10 (Pvalue), size=DEGs) + coord_flip () + scale_color_gradient (low = "green", high = "red") kegg_point

However, it should be noted that in some cases, the number of corresponding DEGs is small, and the size of the automatically matched points is small, so it is difficult to show clearly in the picture, so it can be controlled by scale_size_continuous (range) parameters.

For example:

Kegg_point=kegg_point+scale_size_continuous (range=c (4, 10)) kegg_point

The range parameter corresponding to size can effectively control the range of point size.

These are all the contents of the article "how to draw a Bubble Diagram with ggplot2 in r language". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Bubbles size language content articles parameters learning help control obvious significant effective code geometry functions at the same time pictures coordinates axes genes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft Shulou Technology OPPO Reno NVidia