Ggplot2 Scale Related Settings

Source: Internet
Author: User
Tags ggplot

Ggplot2 Scale Related Settings

Scale settings: Mainly used to adjust settings for each layer after Ggplot drawing.

1. Related attribute scale setting

Includes Scale_size (), Scale_alpha (), Scale_shape ()

As you can see from the name above, these three settings are primarily related to the Ggplot layer properties, including size, transparency, and shape.

The main parameters for this setting are listed below:

SCALE_XXX (name = Waiver (), breaks = waiver (), labels = waiver (), limits = NULL, range = C (1, 6),.....)

As can be seen from the above parameters, we can do this attribute, name name, breaks set Group, Labels Group label, limits limit axis range or group sorting, these parameters are basically used in most scale settings. Range sets the size range, which is relatively rare in other settings.

Here are some examples for reference: R-Band Iris datasets as samples

Library (Ggplot2) P<-ggplot (Iris,aes (sepal.width,sepal.length,size=petal.width)) P+geom_point ()

#标准情况下画出来的散点图

P+geom_point () +scale_size ("Petal width", limits=c (0.2,0.8))

#从可以看到, the name of the legend has been changed, and compared to only a subset of the data, the size of the midpoint of the graph is also magnified, due to the use of the limits parameter qualification, so that data outside the scope of the limit is discarded.

  

P+geom_point () +scale_size ("Petal width", limits=c (0.2,0.8), range=c (1,3))

#在的基础上, after modifying the range parameter, the size scale of the points in the graph is scaled once again, and from the two graph comparison you can see that the limits setting is clipped for the range of the data, and the range setting is purely for the point size.
#另外, it is worth noting that scale_size () is basically used only for scatter plots, and that there is also a Scale_radius () is a set radius on the point, compared to Scale_radius () is rarely used.
#最后scale_size诸多设置也可以用scale_size_area () to set.

  

#接下来, understand the following scale_alpha () related settings, basically similar to scale_size ()
P+geom_point () +scale_alpha ("Petal width", breaks=c (0.2,0.4,0.6,0.8))
#强行对透明度设置自定义分组

  

P+geom_point () +scale_alpha ("Petal width", breaks=c (0.2,0.4,0.6,0.8),                           labels=c ("Very poor", "poor", "good", "very good"))
#对每个分组标签进行重新命名
#另外, Scale_alpha () Many settings can also be set with Scale_alpha_area ()

  

From the above related settings, you can basically understand the above three scale setup process, as well as the role of the relevant parameters.

Finally, in a point: Scale_size () and Scale_alpha () can be used in both discrete and continuous data, whereas Scale_shape can only be used for discrete data.

Ggplot2 Scale Related Settings

Related Article

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.