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