首页 > 代码库 > R语言——绘图函数深入学习

R语言——绘图函数深入学习

利用R自带数据集

通过data()函数可以查看R自带数据集。

> data()

返回以下结果,每一条记录都是一个数据,键入相应的数据名称可以查看具体信息。

Data sets in package ¡®datasets¡¯:AirPassengers             Monthly Airline Passenger Numbers 1949-1960BJsales                   Sales Data with Leading IndicatorBJsales.lead (BJsales)    Sales Data with Leading IndicatorBOD                       Biochemical Oxygen DemandCO2                       Carbon Dioxide Uptake in Grass PlantsChickWeight               Weight versus age of chicks on different dietsDNase                     Elisa assay of DNaseEuStockMarkets            Daily Closing Prices of Major European Stock                          Indices, 1991-1998Formaldehyde              Determination of FormaldehydeHairEyeColor              Hair and Eye Color of Statistics StudentsHarman23.cor              Harman Example 2.3Harman74.cor              Harman Example 7.4

 

例如我们查看mtcars (Motor Trend Car Road Tests)的信息。

> mtcars                     mpg cyl  disp  hp drat    wt  qsec vs am gear carbMazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1Hornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1Hornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2Valiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1Duster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4Merc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2Merc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2Merc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4Merc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3Merc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3Merc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4Fiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1Honda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2Toyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1Toyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1Dodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2AMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2Camaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4Pontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2Fiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1Porsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2Lotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2Ford Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4Ferrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6Maserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8Volvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2

 

经典的鸢尾花数据集,包括花萼长度,花萼宽度,花瓣长度,花瓣宽度,品种 五个属性

共有150条记录。

> iris    Sepal.Length Sepal.Width Petal.Length Petal.Width    Species1            5.1         3.5          1.4         0.2     setosa2            4.9         3.0          1.4         0.2     setosa3            4.7         3.2          1.3         0.2     setosa4            4.6         3.1          1.5         0.2     setosa5            5.0         3.6          1.4         0.2     setosa6            5.4         3.9          1.7         0.4     setosa7            4.6         3.4          1.4         0.3     setosa8            5.0         3.4          1.5         0.2     setosa9            4.4         2.9          1.4         0.2     setosa10           4.9         3.1          1.5         0.1     setosa11           5.4         3.7          1.5         0.2     setosa12           4.8         3.4          1.6         0.2     setosa13           4.8         3.0          1.4         0.1     setosa14           4.3         3.0          1.1         0.1     setosa15           5.8         4.0          1.2         0.2     setosa16           5.7         4.4          1.5         0.4     setosa17           5.4         3.9          1.3         0.4     setosa18           5.1         3.5          1.4         0.3     setosa19           5.7         3.8          1.7         0.3     setosa20           5.1         3.8          1.5         0.3     setosa21           5.4         3.4          1.7         0.2     setosa22           5.1         3.7          1.5         0.4     setosa23           4.6         3.6          1.0         0.2     setosa24           5.1         3.3          1.7         0.5     setosa25           4.8         3.4          1.9         0.2     setosa26           5.0         3.0          1.6         0.2     setosa27           5.0         3.4          1.6         0.4     setosa28           5.2         3.5          1.5         0.2     setosa29           5.2         3.4          1.4         0.2     setosa30           4.7         3.2          1.6         0.2     setosa31           4.8         3.1          1.6         0.2     setosa32           5.4         3.4          1.5         0.4     setosa33           5.2         4.1          1.5         0.1     setosa34           5.5         4.2          1.4         0.2     setosa35           4.9         3.1          1.5         0.2     setosa36           5.0         3.2          1.2         0.2     setosa37           5.5         3.5          1.3         0.2     setosa38           4.9         3.6          1.4         0.1     setosa39           4.4         3.0          1.3         0.2     setosa40           5.1         3.4          1.5         0.2     setosa41           5.0         3.5          1.3         0.3     setosa42           4.5         2.3          1.3         0.3     setosa43           4.4         3.2          1.3         0.2     setosa44           5.0         3.5          1.6         0.6     setosa45           5.1         3.8          1.9         0.4     setosa46           4.8         3.0          1.4         0.3     setosa47           5.1         3.8          1.6         0.2     setosa48           4.6         3.2          1.4         0.2     setosa49           5.3         3.7          1.5         0.2     setosa50           5.0         3.3          1.4         0.2     setosa51           7.0         3.2          4.7         1.4 versicolor52           6.4         3.2          4.5         1.5 versicolor53           6.9         3.1          4.9         1.5 versicolor54           5.5         2.3          4.0         1.3 versicolor55           6.5         2.8          4.6         1.5 versicolor56           5.7         2.8          4.5         1.3 versicolor57           6.3         3.3          4.7         1.6 versicolor58           4.9         2.4          3.3         1.0 versicolor59           6.6         2.9          4.6         1.3 versicolor60           5.2         2.7          3.9         1.4 versicolor61           5.0         2.0          3.5         1.0 versicolor62           5.9         3.0          4.2         1.5 versicolor63           6.0         2.2          4.0         1.0 versicolor64           6.1         2.9          4.7         1.4 versicolor65           5.6         2.9          3.6         1.3 versicolor66           6.7         3.1          4.4         1.4 versicolor67           5.6         3.0          4.5         1.5 versicolor68           5.8         2.7          4.1         1.0 versicolor69           6.2         2.2          4.5         1.5 versicolor70           5.6         2.5          3.9         1.1 versicolor71           5.9         3.2          4.8         1.8 versicolor72           6.1         2.8          4.0         1.3 versicolor73           6.3         2.5          4.9         1.5 versicolor74           6.1         2.8          4.7         1.2 versicolor75           6.4         2.9          4.3         1.3 versicolor76           6.6         3.0          4.4         1.4 versicolor77           6.8         2.8          4.8         1.4 versicolor78           6.7         3.0          5.0         1.7 versicolor79           6.0         2.9          4.5         1.5 versicolor80           5.7         2.6          3.5         1.0 versicolor81           5.5         2.4          3.8         1.1 versicolor82           5.5         2.4          3.7         1.0 versicolor83           5.8         2.7          3.9         1.2 versicolor84           6.0         2.7          5.1         1.6 versicolor85           5.4         3.0          4.5         1.5 versicolor86           6.0         3.4          4.5         1.6 versicolor87           6.7         3.1          4.7         1.5 versicolor88           6.3         2.3          4.4         1.3 versicolor89           5.6         3.0          4.1         1.3 versicolor90           5.5         2.5          4.0         1.3 versicolor91           5.5         2.6          4.4         1.2 versicolor92           6.1         3.0          4.6         1.4 versicolor93           5.8         2.6          4.0         1.2 versicolor94           5.0         2.3          3.3         1.0 versicolor95           5.6         2.7          4.2         1.3 versicolor96           5.7         3.0          4.2         1.2 versicolor97           5.7         2.9          4.2         1.3 versicolor98           6.2         2.9          4.3         1.3 versicolor99           5.1         2.5          3.0         1.1 versicolor100          5.7         2.8          4.1         1.3 versicolor101          6.3         3.3          6.0         2.5  virginica102          5.8         2.7          5.1         1.9  virginica103          7.1         3.0          5.9         2.1  virginica104          6.3         2.9          5.6         1.8  virginica105          6.5         3.0          5.8         2.2  virginica106          7.6         3.0          6.6         2.1  virginica107          4.9         2.5          4.5         1.7  virginica108          7.3         2.9          6.3         1.8  virginica109          6.7         2.5          5.8         1.8  virginica110          7.2         3.6          6.1         2.5  virginica111          6.5         3.2          5.1         2.0  virginica112          6.4         2.7          5.3         1.9  virginica113          6.8         3.0          5.5         2.1  virginica114          5.7         2.5          5.0         2.0  virginica115          5.8         2.8          5.1         2.4  virginica116          6.4         3.2          5.3         2.3  virginica117          6.5         3.0          5.5         1.8  virginica118          7.7         3.8          6.7         2.2  virginica119          7.7         2.6          6.9         2.3  virginica120          6.0         2.2          5.0         1.5  virginica121          6.9         3.2          5.7         2.3  virginica122          5.6         2.8          4.9         2.0  virginica123          7.7         2.8          6.7         2.0  virginica124          6.3         2.7          4.9         1.8  virginica125          6.7         3.3          5.7         2.1  virginica126          7.2         3.2          6.0         1.8  virginica127          6.2         2.8          4.8         1.8  virginica128          6.1         3.0          4.9         1.8  virginica129          6.4         2.8          5.6         2.1  virginica130          7.2         3.0          5.8         1.6  virginica131          7.4         2.8          6.1         1.9  virginica132          7.9         3.8          6.4         2.0  virginica133          6.4         2.8          5.6         2.2  virginica134          6.3         2.8          5.1         1.5  virginica135          6.1         2.6          5.6         1.4  virginica136          7.7         3.0          6.1         2.3  virginica137          6.3         3.4          5.6         2.4  virginica138          6.4         3.1          5.5         1.8  virginica139          6.0         3.0          4.8         1.8  virginica140          6.9         3.1          5.4         2.1  virginica141          6.7         3.1          5.6         2.4  virginica142          6.9         3.1          5.1         2.3  virginica143          5.8         2.7          5.1         1.9  virginica144          6.8         3.2          5.9         2.3  virginica145          6.7         3.3          5.7         2.5  virginica146          6.7         3.0          5.2         2.3  virginica147          6.3         2.5          5.0         1.9  virginica148          6.5         3.0          5.2         2.0  virginica149          6.2         3.4          5.4         2.3  virginica150          5.9         3.0          5.1         1.8  virginica