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 draw violin pictures in R language

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the relevant knowledge of "how to draw violin pictures in R language". In the operation of practical cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The data has been stored in the file, the first thing is to read the data library (readr)

Df%

Filter (auth_num = = 446)-> df1

Df1 $id

Image.pngimage.png

This should have collected the data of a lot of people, and may have listed all the people who participated in the experiment as authors.

Then there is the violin chart showing the distribution of the number of authors in each journal.

The drawing code and results with the original data are as follows

Ggplot (df, aes (x=journal, y=auth_num, fill=journal)) +

Geom_violin (scale= "width") +

Geom_boxplot (width=.12

Fill=I ("black")

Notch=T

Outlier.size=NA

Col= "grey40") +

Stat_summary (fun= "median"

Geom= "point", shape=20, col= "white") +

# scale_y_log10 (breaks=c (1:5, seq (10,50, by=10), 100,200,300) +

Coord_flip () + labs (x = "", y = "Number of authors per paper") +

Theme_classic () + theme (legend.position= "none") +

Scale_fill_brewer ()

Image.png

The result is not very good, and all the authors have done log10 conversion to the original data.

Ggplot (df, aes (x=journal, y=auth_num, fill=journal)) +

Geom_violin (scale= "width") +

Geom_boxplot (width=.12

Fill=I ("black")

Notch=T

Outlier.size=NA

Col= "grey40") +

Stat_summary (fun= "median"

Geom= "point", shape=20, col= "white") +

Scale_y_log10 (breaks=c (1:5, seq (10,50, by=10), 100,200,300) +

Coord_flip () + labs (x = "", y = "Number of authors per paper") +

Theme_classic () + theme (legend.position= "none") +

Scale_fill_brewer ()

Image.png

Log10 conversion is a better solution when the data has obvious outliers.

The new knowledge points learned this time include

The lappy () function specifies parameters

Lapply (files_all

Read_tsv

Col_type= list (

Col_character ()

Col_character ()

Col_character ()

Col_character ())% >%

Bind_rows-> data_all

Count the number of specified characters in a string

Library (stringr)

Str_count ("A _ Magna B _ M C", pattern= ",")

This is the end of the content of "how to draw violin pictures in R language". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Internet Technology

Wechat

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

12
Report