Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Introduction and beautification skills of Box Diagram in R language Visualization

Shulou Source: shulou.com Published: 2022-06-02 06:21:04 10月02日 Update

This article mainly explains "the introduction of box diagram and its beautification skills in R language visualization". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "R language visualization box diagram introduction and its beautification skills" it!

Today, I would like to share with you how to use ggplot function to make box diagram and its beautification in R language.

Box chart is also an important type of chart that is often used to present the distribution of data.

Or take the dataset built into the ggplot2 package as an example to demonstrate:

Ggplot (mpg,aes (class,displ)) + geom_boxplot ()

The above is the simplest form, a classification variable, a continuous numerical type; we add classification variables, so that the box chart can present more data information.

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot ()

Next, as usual, we use the switch of the position parameter to verify the usage rules of the position parameter of the boxplot chart:

Ggplot (diamonds,aes (cut,price,fill=color,alpha=1/30)) + geom_boxplot (position= "identity")

# when the position is set to not make any transformation, the classified box chart will be superimposed on the corresponding X-axis classification items, resulting in occlusion and reading inconvenience. This parameter is not recommended.

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot (position= "stack")

From experience, we can guess that it is estimated that the stacking method to present the multi-dimensional box chart will certainly fail, because even if the classification box chart is really stacked, its function of presenting the data distribution pattern will be lost. sure enough, the software reported an error.

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot (position= "dodge")

Sure enough, when adding multi-classification variables, the default position parameter used in the box chart is dodge.

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot (position= "fill")

Similarly, it makes no sense to set the position parameter to the stacking percentage, and the software fails and warns you.

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot () + facet_grid (. ~ color)

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot () + facet_wrap (~ color)

Carefully understand the difference between the effects of the two facet functions:

Box diagram beautification:

Cluster:

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot () + ggtitle ("Box Plot") + theme_wsj () + scale_fill_wsj () + guides (fill=guide_legend (title=NULL))

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot () + ggtitle ("Box Plot") + theme_economist () + scale_fill_economist () + guides (fill=guide_legend (title=NULL))

Facet:

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot () + ggtitle ("Box Plot") + theme_wsj () + scale_fill_wsj () + guides (fill=guide_legend (title=NULL)) + facet_grid (. ~ color)

Ggplot (diamonds,aes (cut,price,fill=color)) + geom_boxplot () + ggtitle ("Box Plot") + theme_economist () + scale_fill_economist () + guides (fill=guide_legend (title=NULL)) + facet_grid (. ~ color)

At this point, I believe you have a deeper understanding of the "R language visualization box diagram introduction and its beautification skills", might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Diagrams classifications parameters languages data techniques visualization variables content functions charts shapes more software learning practical deeper important inconvenient next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Redmi Apple macOS