"R language Combat" Reading notes--chapter three graphic First order

Source: Internet
Author: User

3.1 Using graphics

You can use functions such as PDFs to save graphics directly in a file. Errors often occur in the use of attach and detach functions, such as naming duplicates, so you should avoid using these two functions as much as possible.

Plot is a general drawing function, Hist is a histogram, and boxplot is a box-type diagram. These functions overwrite the previous graphic, how can I create multiple graphs for easy viewing? There are three methods:

1. Open a new graphics window before creating a new drawing, and each new graphic will appear in the nearest graphics window.

Dev.new() statement 1dev. New () Statement 2 ...

The above statement opens a new window for each image before it appears.

2. Use the forward and backward buttons on the graphical interface.

3. You can use functions such as Dev.new,dev.next,dev.prev,dev.set to open multiple windows at the same time and choose which output to which window. Use Help (Dev.cur) to view the instructions. This looks rather troublesome.

If you place a different graphic in a window, you can first create a 2-row, 3-column graphical collection with par (Mfrow = c (2,3)), and then use plot one to draw the line, as shown in the following:

3.2 A simple example

3.3 Graphics parameters

You can customize multiple features (font, color, axis, title, legend, and so on) for a picture with graphical parameters. The par function can be used to set the graph parameters, to perform par () to view various parameters, add parameter No.readonly = TRUE, you can view the list of parameters that can be modified. It is necessary to note that the setting of par is valid until the software is closed (before the end of the session).

You can record the original parameters and then end a statement before restoring. Like what:

Opar <-par (No.readonly =2) ... par (opar)    #进行还原

Of course, you can set parameters directly after the plot function. Not all parameters can be specified, and the Help function can be used to view specific functions. Some graphical parameters are described below.

3.3.1 Symbols and lines

Open mode:

See below for details:

21-25 can specify the color of the border (col=) and the color of the fill (bg=).

The above is the Linetype setting.

3.3.2 Below is the color setting

The above is a description of the color setting, which needs to be implemented and validated on a specific function. The COL function can be set with numbers, color names, hexadecimal color values, RGB, HSV, and so on. RGB is the primary color, HSV is based on hue, saturation, brightness to generate functions. Colors can view all color names, uh, 657 kinds. The Http://research.stowers-institute.org/efg/R/Color/Chart has a very intuitive color description!

There can be many functions to generate successive colors, Rainrow (), Heat.colors (), Terrain.colors () topo.colors (), Cm.colors (), and so on, the gray function can produce multi-order grayscale, followed by a vector between 0-1.

The pie function is used to appeased the graph, and here is an example:

Par (Mfrow = C (1,2<- Rainbow (n) Pie (Rep (1:  ), labels = mycolors    ,=<-Gray (0: n/N) Pie (Rep (1, N), labels = mygrays,    = mygrays)

Here's the result:

3.3.3 Text Properties

Graphics parameters can specify font size, font, and typeface. The following are the relevant parameter descriptions:

Font families are more difficult to set up.

"R language Combat" Reading notes--chapter three graphic First order

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.