Example of R drawing under Windows

Source: Internet
Author: User

Example 1 :

Read the data from the CITY.XLSX and draw a line chart.

Excel data 1

A b

Figure 1

The code is as follows:

#打开库文件

Library ("xlsx")

#读取excel数据

Data1=read.xlsx ("city.xlsx", Sheetindex = 1)

Data2=read.xlsx ("city.xlsx", Sheetindex = 2)

Data3=read.xlsx ("city.xlsx", Sheetindex = 3)

Data4=read.xlsx ("city.xlsx", Sheetindex = 4)

#给图片命名

PNG (file= "city.jpg")

#绘制第一幅图

Plot (data1$runningtime~data1$length,type= "O", Pch=1,ylim=c (0,5), main= "test", xlab= "Length", ylab= "Running Time", Col= "Blue")

#分别添加图

Lines (data2$runningtime~data2$length,type= "O", pch=2,col= "Red")

Lines (data3$runningtime~data3$length,type= "O", pch=4,col= "green")

Lines (data4$runningtime~data4$length,type= "O", pch=16,col= "Black")

#制作图例

Legend ("TopRight", C ("First", "second", "third", "forth"), bty= ' n ', Pch=c (1,2,4,16), Lty=1,col=c (' Blue ', ' red ', ' green ') , ' black '))

#保存

Dev.off ()

Results:

Example 2 :

Read the data from the city1.xlsx and draw a bar chart.

Excel data 2

Figure 2

Code:

#打开库文件

Library ("xlsx")

#读取excel数据

Data1=read.xlsx ("city1.xlsx", Sheetindex = 3)

Data=data1[,2:5]

M = As.matrix (Data1[,2:5])

PNG (file= "city1.jpg")

#画图

Barplot (M,col=rainbow (4), Ylim=c (0,100), beside=true,legend.text=data1$name,args.legend=list (bty= "n", Horiz=TRUE) )

Dev.off ()

Results:

Example of R drawing under Windows

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.