Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use R language to draw Box Diagram

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use R language to draw a box chart, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Box diagram, also known as box diagram, is often used to show the overall distribution of data, and it is also a kind of figure that often appears in scientific research papers at present. The standard box chart contains several important elements, as shown in the following figure, including the lower quartile (the size of the 25% data), the upper quartile (the size of 75% of the data), the median, and so on. How to draw this kind of box diagram? Here teach you to use the simplest R code to draw the basic box diagram, two lines and three lines to fix the box diagram!

Data preparation

The expression data of 3000 genes from 24 samples were prepared here for drawing. The original data file is a tab-delimited text file. The read data is saved to the vector data. The basic contents of the matrix are as follows (5 lines of data are displayed):

> head (data 5) CK-WT-1 CK-WT-2 CK-WT-3 CK-tdr1-1 CK-tdr1-2 CK-tdr1-3 NaWT-1 NaWT-2 NaWT-3 Natdr1-1AT1G01010 3.741490 7.361800 5.8173400 5.7113100 7.9705400 10.3762000 6.29949 5.550620 5.847790 15.588100AT1G01030 5.235280 2.770700 2.6685900 3.2263200 1.3210500 1.9672600 2.40259 3.230770 4.803780 2.043010AT1G01040 2.821317 1.563395 1.9316282 3.1948090 2.6008540 2.3012776 2.04436 2.104095 2.630611 2.289544AT1G01050 118.660000 140.143000 123.3830000 97.2229000 95.2539000 91.8525000 121.80800 125.135000 106.507000 81.699700AT1G01060 1.873769 16.9025 0.9559375 0.4774184 0.5273923 0.4333881 39.10658 36.530250 19.456131 13.222704 Natdr1-2 Natdr1-3 Na-WT-1 Na-WT-2 Na-WT-3 Na-tdr1-1 Na-tdr1-2 Na-tdr1-3 SWT-1 SWT-2 SWT-3AT1G01010 14.763600 17.746700 9.849430 7.97949 6.841060 13.291200 25.370000 19.599400 4.966870 5.533490 3.188160AT1G01030 2.295240 1.952860 1.833770 1.70757 0.809564 3.231720 1.804780 2.060440 8.492560 2.655640 2.255700AT1G01040 2. 801336 2.450605 3.419992 3.50951 2.388678 3.109170 3.559722 2.699009 3.533361 2.779014 1.973365AT1G01050 84.849500 80.389500 95.484700 93.47060 78.313200 77.220800 93.267700 81.656100 204.019000 251.292000 257.625000AT1G01060 10.889778 12.258010 74.498380 80.83165 22.768773 1.109817 2.482441 34.885769 209.860515 54.164781 11.474413 Stdr1-1 Stdr1-2 Stdr1-3AT1G01010 6.936500 7 . 8840200 11.2504000AT1G01030 4.352980 4.5214700 7.1135100AT1G01040 5.528830 4.9230430 5.6020740AT1G01050 85.227500 77.5347000 84.9365000AT1G01060 3.502854 0.9064844 0.3295299

Box diagram is more suitable for picture display of a large amount of data, so the actual drawing data can come from a variety of statistical data from different studies and different objects, regardless of the gene expression data demonstrated by the case.

Basic drawing

Use the boxplot basic drawing function to draw the box line diagram, in addition to the color and related settings, only one step to draw a complete picture (as below):

Cols=rainbow (24) # for 24 samples, set the color and render the iridescent color as a whole par (cex=0.5) # set the font size boxplot (data,las=2,main= "expression", outline = expression = cols,notch = T) # drawing

The corresponding parameters of the drawing function boxplot used here are explained as follows. If you need to know more parameters, beautify the picture and query the drawing function.

# data drawing Matrix

# las controls the axis label direction

# main Picture title

# whether outline displays outliers

# col Image Color

# does notch show wedge-shaped engraving

The above is all the contents of the article "how to draw a Box Diagram 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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report