Ggplot2 Geom Related Settings-distribution map

Source: Internet
Author: User
Tags ggplot

Distribution in R should be regarded as a relatively important content, and by drawing to show the distribution of data, you can more intuitively let us understand the distribution of data

Histogram

Geom_histogram (mapping = NULL, data = NULL, stat = "bin", Position = "stack", ..., binwidth = null, bins = NULL, NA.RM = F Alse, show.legend = NA, Inherit.aes = TRUE)

Density map

geom_density (mapping = NULL, data = NULL, stat = "density", Position = "identity", ..., na.rm = FALSE, show.legend = na, I Nherit.aes = TRUE)

The histogram shows the distribution of the data through a huge stack height, and the density graph shows the distribution of the data through linear bending.

Let's look at a concrete example.

Library (Ggplot2) P<-ggplot (Diamonds, AES (carat)) P+geom_histogram (bins=30)

Let's look at the effect of using a density map

P+geom_density ()

The density graph looks smoother than the histogram, and continues to look at the stack case comparison

P<-ggplot (Diamonds, AES (Carat,fill=cut)) P+geom_histogram (BINS=50)

P+geom_density (position= "stack", adjust=1/1.2)

  

Here in the future to avoid the various categorical variable data occlusion, the value of the parameter position set to stack, you can show a layer of the effect of stacking up

In addition, the parameter adjust can be similar to the parameter bins in the histogram for adjusting the width of the strip or rectangle

P+geom_density (position= "Fill", adjust=1/1.2)

  

Setting the position to fill gives you a more intuitive look at the density of each classification, but the axes ' indication effect is blurred.

Ggplot2 Geom Related Settings-distribution map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.