Example of R drawing using Linux

Source: Internet
Author: User

Read the data from City1.csv, City2.csv, City3.csv, City4.csv, and draw a line chart.

CSV Data 1

A b

Figure 1

The code is as follows:

#读取csv数据

Data1=read.csv ("City1.csv")

Data2=read.csv ("City2.csv")

Data3=read.csv ("City3.csv")

Data4=read.csv ("City4.csv")

#给图片命名

PNG (file= "city1.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 City.csv and draw a bar chart.

CSV Data 2

Figure 2

Code:

#读取csv数据

Data1=read.csv ("City.csv")

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

PNG (file= "city.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 using Linux

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.