Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to draw violin pictures in R language

Shulou Source: shulou.com Published: 2022-06-01 22:02:20 10月02日 Update

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!

Tags: Data author violin quantity knowledge language original next content function character situation more journal result good-looking practical obvious learned median Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Huawei MySQL Xiaomi Shulou Tech Info