R Language Note Plot drawing

Source: Internet
Author: User

Plot () is a generic function that is plotted for an object in R (its output will vary depending on the type of object being drawn).

In this example, plot (x, y, type= "B") puts X on the horizontal axis, places y on the vertical, draws the point set (x, Y), and then uses the segment

To connect it. The option type= "B" indicates that both points and lines are plotted. Use Help (plot) to see other options. Results such as

As shown in Figure 3-2.

> Dose <-C (20,30,40,45,60)

> Druga <-c (16,20,27,40,60)

> DRUGB <-c (15,18,25,31,40)

> Plot (Dose,druga)

> Plot (dose,druga,type= "B")

Type types

What type of plot should is drawn. Possible types is

    • "p"For Points,

    • "l"For lInes,

    • "b"For both,

    • "c"For the lines part alone "b" of,

    • "o"For both 'overplotted ',

    • "h"For 'histogram ' like (or ' high-density ') vertical lines,

    • "s"For stair steps,

    • "S"For other steps, see ' Details ' below,

    • "n"For no plotting.



> Plot (dose,druga,type= "B", cex=2,lty=2,pch=18,lwd=2)


PCH specifies the symbol to use when drawing points (0 ... 24 types)

CEX Specifies the size of the symbol. CeX is a numeric value that represents the zoom factor of the drawing symbol relative to the default size. Default size

1.5 times times the default value for 1,1.5, 0.5 for the default value of 50%, and so on

Lty Specifying line type (1,2,3,4,5,6,7)

LWD specifies the line width. The LWD is represented by the relative size of the default value (the default value is 1). For example, lwd=2 will be born

into a line twice the default width

You can also specify the border color (col=) and the fill Color (bg=).

--------------Color--------------

The default drawing color for Col. Some functions, such as lines and pie, can accept a vector that contains a color value

And it is automatically recycled. For example, if you set Col=c ("Red", "blue") and need to draw three lines,

Then the first line will be red, the second line is blue, and the third line will be the red one.

Col.axis the color of the axis scale text

Col.lab the color of the axis label (name)

Col.main title Color

Col.sub subtitle Color

foreground color of FG graphics

Background color for BG Graphics


In R, you can specify a color by color subscript, color name, hexadecimal color value, RGB value, or HSV value.

For example, col=1, col= "white", col= "#FFFFFF", Col=rgb (1,1,1) and COL=HSV (0,0,1)

is an equivalent way of representing white. The function RGB () can generate colors based on red-green-blue tri-color values, whereas HSV () is based on hue-

Saturation-the luminance value to generate the color. Please refer to the Help for these functions for more details.

The function colors () can return the names of all available colors. Earl F. Glynn created a good for the colors in R

Online charts, see Http://research.stowers-institute.org/efg/R/Color/Chart. There are also several types of r used to create continuous

Functions of the type color vector, including Rainbow (), Heat.colors (), Terrain.colors (), Topo.colors ()

and Cm.colors (). For example, Rainbow (10) can generate 10 consecutive "rainbow" colors. Multi-order Grayscale

Colors can be generated using the gray () function. The grayscale of each color is specified by a vector that has an element value between 0 and 1.

Gray (0:10/10) will generate 10-step grayscale color

> n=10

> Mycolors<-rainbow (N)

> Pie (Rep (1,n), lables=mycolors,col=mycolors)

> Mygrays<-gray (1:n/n)

> dev.new ()

> Pie (Rep (1,n), lables=mygrays,col=mygrays)


------Text Properties----

CeX represents a numeric value relative to the default size scale multiplier. The default size is 1,1.5, which means 1.5 of the default value is enlarged.

Times, 0.5 is reduced to 50% of the default value, and so on

Cex.axis the scale multiples of the axis scale text. Similar to CeX

Cex.lab the zoom factor of the axis label (name). Similar to CeX

Cex.main the zoom multiplier of the caption. Similar to CeX

Cex.sub the zoom multiplier of the subtitle. Similar to CeX

A font integer. Used to specify the font style used by the drawing. 1= general, 2 = bold, 3 = italic, 4 = Bold Italic, 5 =

Symbol font (denoted by the Adobe symbol encoding)

Font.axis font style for axis scale text

Font.lab font style for axis labels (names)

Font.main font style for headings

Font style for font.sub subtitle

PS Font point size (approx. 1 lbs. 1/72 in.). The final size of the text is Ps*cex

Family the font family used when drawing text. Standard values are serif (liner), sans (sans serif), and mono

(Equal width)

----------Border--------

The graphic size (width and height) of the pin in inches

Mai the size of the boundary as a numeric vector, in order "bottom, left, top, right", in inches

Mar represents the size of the boundary as a numeric vector, in the order of "bottom, left, top, and right", in English per cent. The default value is C (5, 4, 4, 2) + 0.1

-----------Add a text axis----

In addition to graphical parameters, many advanced drawing functions (such as plot, Hist, boxplot) also allow you to set your own axes

and text labeling options. For example, the following code adds a caption (main), subtitle (sub), axis label

(Xlab, Ylab) and specify the axis range (Xlim, Ylim)


Write these first, and then finish them up.

R Language Note Plot drawing

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.