R language Drawing

Source: Internet
Author: User

In the R language, drawing is simply too convenient, too powerful, and a few commands can take a curve.

First, drawing equipment

The drawing devices in the R language contain two types: windows and graphics devices.

The window device is the X11 Class (X Window System), and the graphics device can contain a variety of output formats Pdf,metafile, PNG, JPEG, BMP, TIFF, XFig, and PostScript. Use a window device drawing graphic to output directly to a child window of the R UI, use a graphics device to output to a file, the default device is a window device, and when you enter a drawing command, a drawing window is opened by default, and subsequent drawings use the drawing window.

Drawing device-related commands:

1. Display drawing device information

Dev.list ()

Shows a few drawing devices, and the corresponding device number.

2. Display the current device

Dev.cur ()

Displays the current drawing device type and device number.

3. Opening the drawing device

(1) Open the Graphics device window

X11 ()

(2) Open the Graphics device window

PDF ("R-graph.pdf")

Output to PDF file

png ("R-graph.png")

Output to PNG file

4. Close the drawing device

(1) Turn off the drawing device for the specified device number

Dev.off (2)

Turn off the drawing device with device number 2, and then use Dev.list () to see if the device is turned off.

(2) Close all drawing devices

Graphics.off ()

Close all drawing windows and graphics devices.

Ii. examples

1. Experiment: Open a graphics device and export the drawing to a file

dev.list () #查看所有绘图设备

PDF ("R-graph.pdf") #打开一个pdf类型的绘图设备, the output file is named "R-graph.pdf"

dev.cur () #显示当前绘图设备号

plot (cpu1,type= "L") #cpu1为一个数据列, the output graph is a curve

Dev.off () #关闭当前设备

The result should be in the output directory (default in My Documents in Windows) and you should be able to find a PDF file with the name R-graph.pdf, and the file content to be drawn in the R language.

III. Expansion of applications

1. Open multiple drawing windows at the same time for drawing comparison.

X11 ()

Need a few to lose like a few times.

To navigate to a window:

Dev.set (3)

The argument is a parameter ordinal in parentheses.


Reference:

1, the green SAC Taoist blog,http://blog.sina.com.cn/s/blog_5de124240101pzld.html.

2. Robert I. Kabacoff,r language practice [M], Beijing, people's post and telecommunications publishing house, 2013.1,p40.


R language 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.