R Language Basics Learning (iv): The Paint function--plot () function in R

Source: Internet
Author: User

The plot () function is a function of the basic X-y two variables in R, which is used as follows: Plot (x, Y, ...)

For example: First I use the runif () function to produce two columns of random numbers: x1,y1, and then draw directly with the plot () function:

> X1 <-Round (runif (20,min = 0, max = 100))
> x1
[1] 90 84 86 86 28 43 86 76 90 76 14 62 40 52 87 57 88 17
[19] 10 27
> Y1 <-Round (runif (20,min = 0, max = 100))
> y1
[1] 23 91 75 72 4 60 23 50 74 92 55 56 21 86 71 86 84 47
[19] 4 79
> Plot (x1,y1)

This is the default paint style for the plot () function. You can add additional parameters to change the style of the diagram.

Cases:

> Plot (x1,y1,main = "I am the title", Xlab = "I am the x axis", Ylab = "I am the y axis", Xlim = C (0,100), Ylim = C (0,100), col = "Red", PCH = 19)

The illustrations are:

Parameter description:

Main: Title

Xlab,ylab:x,y Axis Description

Scale limits for xlim,ylim:x,y axes

Col: The color of the stroke

PCH: The style of the stroke, the 19 code is a solid dot, can also be replaced by other codes.

The above is a scatter plot with the plot () function, and the plot () function can also draw a line chart, for example:

> x <-C (1:10)
> y <-Round (runif (10,min = x, max = 100))
> Plot (x,y,type = ' l ', Ylim = C (60,100))

X is 1-10 10 digits, Y is the score of 10 exams, you can draw a line chart of these 10 test scores:

The plot () function can also draw multiple line graphs with the lines () function:

> x <-1:10
> Beijing <-Round (rnorm (10,mean = $, SD = 2), 1)
> Shanghai <-Round (rnorm (10,mean = $, SD = 3), 1)
> Guangzhou <-Round (rnorm (10,mean = $, SD = 1), 1)

> Plot (x,beijing,type = ' l ', Ylim = C (16,30), LWD = 2,main = "Temperature change trend in Beijing, Shanghai and Guangzhou for the last 10 days")
> lines (x,shanghai,type = ' l ', col = ' Blue ', LWD = 2)
> lines (x,guangzhou,type = ' l ', col = ' red ', LWD = 2)

Note: the lines () function must be used in conjunction with the plot () function to draw a graph with the plot () function and then add the lines () function to the other lines.

Learn here today, and then next week to learn

R Language Basics Learning (iv): The Paint function--plot () function in R

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.