3 Figures and graphics basics

file_location <- "C:/YourFolder/Data/soil_data.txt"
soil_data <- read.table(file_location, header = TRUE)
names(soil_data)
##  [1] "OBJECTID" "x"        "y"        "coarse"   "clay"     "silt"    
##  [7] "sand"     "pH"       "OC"       "N"        "P"        "K"       
## [13] "CEC"      "pH_class"
str(soil_data)
## 'data.frame':    346 obs. of  14 variables:
##  $ OBJECTID: int  1 2 3 4 5 6 7 8 9 10 ...
##  $ x       : num  789504 773300 773621 766972 765574 ...
##  $ y       : num  5318238 5334066 5308045 5360016 5311956 ...
##  $ coarse  : int  12 8 14 13 12 5 50 5 35 9 ...
##  $ clay    : int  21 23 22 17 18 17 22 19 21 33 ...
##  $ silt    : int  41 72 58 54 56 74 39 63 69 60 ...
##  $ sand    : int  38 5 20 28 27 9 39 18 10 7 ...
##  $ pH      : num  6.32 5.56 5.1 7.34 6.12 6.6 7.2 7.39 7.02 6.24 ...
##  $ OC      : num  17.8 18 27.7 12.5 31.5 ...
##  $ N       : num  1.8 1.8 2.5 1.4 3.2 ...
##  $ P       : num  20.1 60.6 15 27.6 24.1 55.6 49.3 84.2 76.6 54.4 ...
##  $ K       : num  126.8 234.3 70.1 17.6 68.1 ...
##  $ CEC     : num  12.6 10.4 8.3 12.7 18.7 12.9 36 16.5 22.5 27.5 ...
##  $ pH_class: chr  "acidic" "acidic" "acidic" "neutral" ...
OBJECTID x y coarse clay silt sand pH OC N P K CEC pH_class
1 789503.5 5318238 12 21 41 38 6.32 17.8 1.8 20.1 126.8 12.6 acidic
2 773299.8 5334066 8 23 72 5 5.56 18.0 1.8 60.6 234.3 10.4 acidic
3 773620.8 5308045 14 22 58 20 5.10 27.7 2.5 15.0 70.1 8.3 acidic
4 766972.2 5360016 13 17 54 28 7.34 12.5 1.4 27.6 17.6 12.7 neutral
5 765574.1 5311956 12 18 56 27 6.12 31.5 3.2 24.1 68.1 18.7 acidic
6 763222.3 5339957 5 17 74 9 6.60 12.4 1.4 55.6 123.9 12.9 neutral
7 763674.4 5303926 50 22 39 39 7.20 103.3 7.7 49.3 111.9 36.0 neutral
8 759071.3 5351917 5 19 63 18 7.39 17.0 1.9 84.2 0.0 16.5 neutral
9 759246.5 5337908 35 21 69 10 7.02 36.1 3.8 76.6 74.0 22.5 neutral
10 759699.9 5301880 9 33 60 7 6.24 72.8 6.7 54.4 764.4 27.5 acidic
11 756896.7 5365899 27 21 38 42 6.15 19.1 1.7 68.1 241.7 10.8 acidic
12 754942.4 5361877 20 17 57 26 6.72 15.2 1.7 74.6 139.7 15.0 neutral
13 753585.4 5311848 23 14 56 30 7.54 30.7 3.0 72.7 107.9 21.3 alkaline
14 749375.0 5327783 33 17 45 38 5.44 17.4 1.8 44.7 96.5 7.8 acidic
15 747123.7 5347773 17 20 63 17 7.29 20.2 2.2 19.6 94.9 16.6 neutral
16 745452.8 5321736 47 28 42 30 6.89 57.1 5.4 17.9 87.9 31.4 neutral
17 741023.2 5355707 29 25 54 21 7.32 50.4 5.4 86.0 657.7 33.9 neutral
18 741425.8 5323691 9 8 39 53 7.43 11.1 1.2 0.0 132.1 9.5 neutral
19 737249.5 5337649 20 16 41 44 7.26 30.2 2.9 64.6 210.0 30.2 neutral
20 737530.0 5315635 16 18 52 30 7.03 38.0 3.7 35.2 191.7 20.7 neutral
21 735121.1 5347621 4 19 54 28 3.81 49.5 3.0 24.2 45.1 10.6 acidic
22 735350.4 5329623 19 19 47 34 6.85 40.4 4.7 86.6 187.4 19.4 neutral
23 733300.3 5333599 34 18 65 17 7.61 30.5 2.7 48.2 145.2 17.8 alkaline
24 733754.7 5297578 25 7 37 55 7.24 32.2 2.5 10.6 35.0 13.6 neutral
25 728897.7 5365571 14 22 52 26 6.80 15.8 1.7 42.1 106.4 16.4 neutral
26 729505.9 5317542 18 31 53 17 6.19 83.7 8.5 33.6 106.9 35.2 acidic
27 729805.0 5293528 23 41 45 15 6.39 41.1 4.0 15.5 116.8 24.4 acidic
28 725505.1 5317497 27 18 43 39 6.87 197.3 12.5 42.9 102.4 73.7 neutral
29 723759.1 5297460 19 31 56 13 7.13 68.9 6.6 65.1 125.3 40.8 neutral
30 719027.6 5355448 15 14 73 12 7.51 11.2 1.3 71.2 187.5 12.2 alkaline
31 719633.5 5307419 21 28 36 36 6.16 33.5 3.2 23.7 162.4 24.6 acidic
32 714798.8 5373406 4 22 69 9 7.44 12.3 1.4 59.3 313.3 17.5 neutral
33 713154.9 5345368 14 27 69 3 6.46 21.0 2.2 40.0 79.6 18.4 acidic
34 707370.6 5335263 28 22 45 33 7.84 28.3 2.7 73.6 324.7 24.1 alkaline
35 704857.7 5369280 24 22 44 35 7.52 33.8 3.4 79.2 88.8 27.5 alkaline
36 705765.8 5297246 17 26 57 18 5.23 45.7 4.3 41.1 116.6 13.5 acidic
37 700340.3 5409247 11 23 54 23 8.14 38.2 2.6 21.0 104.5 24.4 alkaline
38 700623.5 5387240 7 27 60 13 6.77 17.9 1.9 53.2 337.7 14.7 neutral
39 700957.7 5361230 3 40 53 7 7.65 63.4 5.7 15.5 92.9 55.3 alkaline
40 701084.6 5351227 10 28 60 12 7.58 68.1 5.5 51.1 117.0 50.9 alkaline
41 694472.1 5399168 19 6 11 84 5.58 6.2 0.7 73.9 100.5 3.5 acidic
42 694933.8 5363158 19 15 38 48 6.24 10.3 1.3 35.0 176.8 6.8 acidic
43 692830.7 5371134 12 13 41 46 6.61 15.0 1.6 59.1 190.7 8.1 neutral
44 690239.9 5417126 9 26 59 15 7.69 18.2 1.7 24.1 119.6 20.6 alkaline
45 690317.1 5411119 16 23 64 13 7.95 20.1 1.8 62.3 20.5 20.3 alkaline
46 690703.2 5381116 15 20 55 25 7.06 14.9 1.5 92.2 235.4 15.2 neutral
47 691163.3 5345102 42 19 39 42 7.56 37.7 3.7 37.8 366.6 25.1 alkaline
48 686111.6 5427077 8 23 68 8 7.01 16.9 1.8 90.9 387.1 15.1 neutral
49 686577.7 5391068 5 21 23 56 6.84 28.2 3.0 10.7 0.0 20.9 neutral
50 687674.8 5305036 7 33 39 28 6.96 54.4 5.6 33.1 218.5 34.5 neutral
51 685600.6 5311015 26 19 48 33 7.31 38.7 3.8 10.3 122.6 31.1 neutral
52 680372.4 5406996 5 17 48 34 6.33 12.3 1.5 52.0 184.0 8.5 acidic
53 680449.6 5400997 21 25 50 25 7.66 35.3 2.1 47.8 291.5 20.5 alkaline
54 680604.4 5388992 5 6 14 80 7.56 32.8 2.4 13.3 135.2 18.3 alkaline
55 680683.4 5382991 6 10 21 69 6.25 8.9 1.1 35.0 199.1 5.9 acidic
56 680914.2 5364990 5 18 62 20 5.72 11.6 1.2 40.1 146.4 9.2 acidic
57 681066.5 5352983 2 36 37 26 6.44 28.4 2.9 23.9 115.1 26.8 acidic
58 676710.0 5380941 14 13 45 43 5.54 13.4 1.6 31.9 120.7 8.2 acidic
59 676996.0 5358943 14 15 26 59 7.46 16.2 1.6 84.5 121.5 14.7 neutral
60 672246.2 5416900 18 30 49 21 7.89 32.3 2.2 98.2 425.6 23.6 alkaline
61 672323.6 5410899 4 15 31 54 7.16 13.0 1.3 53.4 399.8 10.0 neutral
62 673351.6 5330876 8 9 65 26 6.69 13.2 1.5 67.4 128.0 11.2 neutral
63 673875.4 5290858 11 16 52 32 7.40 44.2 4.2 13.4 168.4 36.6 neutral
64 669043.9 5354836 9 18 37 45 6.75 13.1 1.6 94.6 262.2 12.0 neutral
65 669097.6 5350835 0 18 28 53 6.02 47.3 4.1 40.0 102.3 21.6 acidic
66 664505.2 5396794 12 11 14 74 7.33 29.1 2.3 0.0 264.5 17.1 neutral
67 664637.5 5386795 1 7 10 82 5.97 73.8 5.8 23.7 373.3 29.0 acidic
68 665892.2 5288761 34 20 49 31 6.84 37.3 3.4 20.0 193.5 27.9 neutral
69 664070.1 5274732 21 62 38 1 6.69 113.5 9.8 11.3 192.6 63.8 neutral
70 658251.4 5416723 23 39 35 26 7.69 32.8 3.0 77.0 467.0 27.9 alkaline
71 657845.6 5292668 16 45 43 12 6.80 123.8 8.6 17.4 156.6 64.7 neutral
72 654331.6 5410671 11 23 61 16 6.54 12.6 1.4 53.2 147.2 13.9 neutral
73 650434.7 5404620 10 29 54 17 7.33 27.2 1.9 95.4 543.3 22.1 neutral
74 651339.4 5332605 16 27 53 20 6.79 32.2 3.2 50.6 57.4 22.3 neutral
75 651748.9 5300596 2 23 41 36 6.35 40.1 4.1 47.8 151.0 20.3 acidic
76 647675.0 5306549 0 36 49 16 5.67 63.2 5.4 0.0 99.7 28.5 acidic
77 641883.8 5290470 10 31 50 19 5.84 50.8 5.2 21.1 115.5 29.0 acidic
78 633763.7 5300372 3 17 61 22 6.84 53.5 5.7 13.5 166.6 32.5 neutral
79 779726.1 5458249 7 17 37 46 6.49 57.3 5.2 16.0 67.4 17.5 acidic
80 775645.8 5464203 10 16 35 48 6.35 15.6 1.6 76.6 543.1 10.1 acidic
81 771799.3 5452147 17 11 28 61 7.07 17.4 1.7 139.4 688.1 7.0 neutral
82 765772.8 5454076 17 13 27 59 6.27 21.0 1.9 74.5 482.4 9.2 acidic
83 761720.6 5458028 3 23 44 33 5.59 24.4 2.4 43.3 282.1 9.5 acidic
84 757460.7 5477988 8 20 36 44 7.20 15.8 1.6 65.7 414.3 14.6 neutral
85 753173.0 5499946 6 17 51 31 7.00 15.7 1.5 51.8 183.2 9.9 neutral
86 751899.5 5443901 24 21 38 41 6.18 29.5 2.5 14.6 213.3 13.6 acidic
87 747536.9 5471862 30 10 26 64 6.20 12.5 1.3 63.5 130.9 7.4 acidic
88 747820.6 5449854 27 8 24 69 5.37 9.3 1.0 147.3 280.6 6.5 acidic
89 748051.9 5431845 22 22 61 17 8.08 31.1 2.4 45.2 138.7 20.6 alkaline
90 744805.7 5527855 13 18 30 52 5.34 62.7 5.2 15.0 58.6 15.9 acidic
91 746127.0 5425818 5 38 46 16 7.26 54.2 5.2 22.9 196.4 38.1 neutral
92 738751.2 5531779 9 18 34 47 6.69 16.5 1.4 95.8 218.3 11.8 neutral
93 739118.4 5503778 9 15 32 53 5.96 30.7 2.4 17.2 138.3 10.9 acidic
94 739405.1 5481764 5 23 37 40 6.07 29.8 2.9 15.7 76.6 14.3 acidic
95 735325.8 5487720 9 13 29 58 7.07 12.6 1.3 45.5 194.3 13.9 neutral
96 735871.1 5445705 18 16 33 50 5.78 22.1 2.3 50.0 305.7 10.2 acidic
97 732802.2 5527702 19 15 34 51 5.46 32.0 2.7 69.0 71.0 7.6 acidic
98 733430.1 5479691 14 11 39 51 7.21 13.9 1.4 59.4 155.2 12.9 neutral
99 730934.1 5517675 12 11 32 57 5.24 15.2 1.7 38.9 79.2 10.3 acidic
100 731168.6 5499671 15 10 23 67 5.93 9.1 1.1 49.8 243.8 5.1 acidic
101 732103.6 5427645 22 24 70 6 7.36 16.6 1.8 54.0 665.6 18.8 neutral
102 729586.7 5467637 5 8 13 79 7.07 14.4 1.2 43.5 189.0 7.4 neutral
103 727746.0 5455610 19 51 42 7 5.60 48.9 4.4 0.0 99.5 20.8 acidic
104 727896.5 5443603 9 8 24 68 6.17 9.8 0.9 76.2 145.7 4.8 acidic
105 722052.4 5431527 5 20 49 31 7.25 12.9 1.4 48.8 167.8 14.2 neutral
106 717559.4 5469493 6 14 8 77 7.39 7.9 0.9 30.5 166.7 10.4 neutral
107 711117.0 5503418 5 11 15 73 5.49 23.8 1.8 41.2 42.9 8.8 acidic
108 708801.8 5527395 7 20 25 55 5.70 23.0 2.2 17.3 120.8 8.4 acidic
109 709976.3 5437380 8 36 53 11 7.50 20.5 2.0 49.4 308.9 22.8 alkaline
110 706774.9 5529370 8 44 45 12 7.61 33.7 3.2 20.4 203.5 24.6 alkaline
111 704958.2 5515346 3 7 18 75 6.17 10.3 1.1 51.8 90.1 7.5 acidic
112 703169.4 5499315 4 30 33 37 5.90 36.8 3.2 10.3 68.9 13.4 acidic
113 703404.7 5481313 4 18 67 16 7.12 11.3 1.2 25.0 209.6 10.2 neutral
114 701274.9 5491289 5 18 45 37 6.53 22.9 2.0 29.1 53.5 9.6 neutral
115 699924.5 5441255 11 24 68 8 6.49 21.7 2.1 82.1 289.9 16.9 acidic
116 695873.4 5445206 28 26 60 14 7.11 22.7 2.4 87.3 529.5 17.7 neutral
117 690960.2 5515165 8 17 41 42 5.35 23.5 2.2 0.0 45.5 4.7 acidic
118 690084.8 5429127 11 26 63 11 7.16 17.3 1.8 22.3 233.5 14.6 neutral
119 687434.2 5479110 9 22 66 12 7.91 12.7 1.4 25.7 210.2 16.0 alkaline
120 687668.7 5461108 23 21 67 12 6.38 15.2 1.6 50.9 193.3 12.2 acidic
121 685878.0 5445078 13 21 69 9 7.55 16.0 1.6 28.5 219.8 17.1 alkaline
122 683512.7 5473059 26 25 36 40 6.93 13.1 1.4 26.8 0.0 10.1 neutral
123 677699.3 5458981 3 8 6 85 5.97 25.2 2.3 27.6 118.6 7.7 acidic
124 673751.7 5454931 3 24 12 64 6.00 22.3 2.1 64.3 139.8 12.3 acidic
125 632496.6 5550407 5 23 39 38 7.38 14.6 1.6 24.4 247.1 15.4 neutral
126 620422.9 5556246 10 27 21 52 7.43 14.2 1.5 52.7 471.5 17.1 neutral
127 610587.0 5544117 2 52 32 16 8.12 18.8 1.8 78.4 537.9 25.5 alkaline
128 608534.3 5548089 13 31 58 11 7.09 30.8 3.0 14.1 145.2 25.5 neutral
129 606269.1 5568058 7 41 41 18 7.12 45.2 3.7 35.1 263.4 26.5 neutral
130 605018.0 5512044 7 17 31 52 7.15 11.0 1.1 42.7 254.1 11.8 neutral
131 600405.0 5557980 13 21 72 7 6.34 14.7 1.6 22.8 177.0 12.8 acidic
132 598565.7 5545956 9 13 48 39 6.91 14.6 1.6 23.8 151.1 11.2 neutral
133 596031.5 5585920 4 44 47 9 6.45 21.7 2.4 28.8 431.6 20.3 acidic
134 594246.2 5569895 29 30 66 4 7.53 16.9 1.7 27.7 233.2 20.5 alkaline
135 594676.1 5537907 8 25 25 50 7.71 14.8 1.6 23.2 524.4 16.1 alkaline
136 594967.4 5515911 3 17 27 56 6.18 21.0 2.2 11.3 56.7 12.9 acidic
137 590890.7 5521855 4 32 27 42 8.02 12.2 1.3 53.3 421.6 12.3 alkaline
138 591128.2 5503860 11 39 49 12 8.05 17.7 1.4 40.0 643.0 18.9 alkaline
139 589081.3 5507835 7 20 32 48 7.23 6.3 0.7 25.1 178.2 10.4 neutral
140 586544.7 5547797 11 21 74 5 6.85 10.2 1.3 41.6 259.1 12.5 neutral
141 583967.2 5591742 5 33 59 8 7.62 32.9 3.4 32.2 349.4 34.4 alkaline
142 584918.3 5519778 4 36 60 5 7.93 17.5 1.8 65.7 585.7 19.5 alkaline
143 582760.7 5531749 11 29 63 8 8.14 12.9 1.5 38.9 355.1 19.8 alkaline
144 580709.7 5535722 17 25 72 3 7.90 13.1 1.5 20.3 239.5 19.2 alkaline
145 577029.7 5511675 11 22 64 14 7.12 11.5 1.3 51.4 196.2 14.2 neutral
146 572551.0 5547611 27 24 62 15 6.90 38.0 3.0 35.7 356.5 26.0 neutral
147 570044.3 5585571 10 12 19 69 5.85 17.2 1.5 18.2 112.3 8.0 acidic
148 570267.7 5567576 11 13 42 45 6.61 9.6 1.1 29.0 143.5 6.0 neutral
149 569275.2 5493572 4 26 72 2 7.79 12.4 1.5 36.8 196.8 14.6 alkaline
150 566877.0 5523538 44 38 52 10 8.12 20.1 2.0 70.1 534.0 26.0 alkaline
151 567113.1 5505545 7 36 59 5 7.09 21.6 2.7 22.0 245.4 25.1 neutral
152 564420.8 5557500 14 16 47 37 7.39 24.2 2.3 17.9 279.1 14.2 neutral
153 562717.9 5535478 4 42 54 4 6.85 12.5 1.4 29.6 322.0 24.5 neutral
154 558799.2 5529428 12 7 14 79 7.75 8.4 0.8 30.0 65.8 8.4 alkaline
155 554079.1 5583355 5 18 42 40 5.36 24.6 2.4 19.2 247.2 5.4 acidic
156 554991.9 5515379 14 27 66 8 7.91 10.7 1.4 34.7 194.4 18.5 alkaline
157 552857.6 5525351 8 17 78 5 7.06 12.4 1.5 68.3 274.2 14.5 neutral
158 553024.3 5513351 23 33 63 4 7.45 16.6 1.7 37.0 365.6 21.2 neutral
159 519172.3 5502901 5 14 40 45 5.96 14.9 1.4 56.3 245.4 7.6 acidic
160 510618.5 5542815 10 15 27 58 6.31 14.0 1.4 48.1 248.0 8.0 acidic
161 508615.3 5544746 16 14 25 61 5.82 8.7 1.0 44.9 142.5 8.5 acidic
162 508892.7 5526799 3 17 67 15 6.62 8.4 1.1 22.6 107.8 10.4 neutral
163 718600.3 5545446 13 12 55 33 6.71 17.2 1.8 42.6 144.8 8.7 neutral
164 712460.6 5553452 17 21 41 38 5.89 25.0 2.1 70.0 208.3 9.3 acidic
165 710165.2 5575427 36 18 53 29 7.19 17.1 1.6 41.0 85.9 16.0 neutral
166 698377.9 5559270 20 16 33 51 5.18 30.5 2.4 11.4 48.7 7.3 acidic
167 690564.4 5545167 18 28 36 36 6.07 25.4 2.6 10.6 88.5 17.5 acidic
168 686724.1 5533114 7 14 20 66 6.06 10.4 1.1 0.0 62.2 8.3 acidic
169 678247.5 5569008 6 17 40 43 6.31 30.8 2.8 0.0 151.6 12.9 acidic
170 676698.8 5534984 10 28 52 21 5.13 27.8 2.8 0.0 91.6 14.1 acidic
171 674831.1 5524958 34 38 46 16 7.74 43.2 3.9 143.2 652.7 35.4 alkaline
172 670433.2 5554906 6 38 49 13 7.07 29.7 2.9 45.0 475.5 25.0 neutral
173 668727.3 5532878 19 27 57 16 7.65 29.4 2.8 108.5 406.7 24.3 alkaline
174 664330.0 5562825 9 19 70 11 6.13 13.5 1.4 41.2 201.0 12.6 acidic
175 663096.3 5504801 2 30 58 12 6.44 20.9 2.1 13.4 82.7 17.9 acidic
176 656650.9 5538721 19 37 51 11 7.60 18.9 1.9 19.0 271.3 23.1 alkaline
177 654332.3 5562693 5 14 41 45 6.86 15.4 1.5 35.5 116.4 12.1 neutral
178 654489.6 5550694 33 41 49 9 7.39 38.7 3.7 58.9 943.0 37.3 neutral
179 654811.6 5526698 12 40 45 15 7.78 36.6 3.2 71.6 747.8 32.0 alkaline
180 655043.8 5508700 8 33 30 38 7.95 15.3 1.8 34.0 295.9 17.6 alkaline
181 648280.5 5566615 18 47 46 7 7.49 32.0 3.1 64.1 609.8 29.9 neutral
182 644521.5 5548565 47 59 36 5 5.91 48.5 4.8 0.0 405.3 30.5 acidic
183 640709.2 5534517 12 19 29 52 7.46 19.1 2.0 22.2 155.6 14.7 neutral
184 638841.6 5524488 13 20 16 64 6.83 22.8 2.1 27.0 99.0 23.8 neutral
185 636733.6 5532461 21 68 23 9 6.35 61.2 6.1 12.0 150.9 39.0 acidic
186 634925.9 5518440 6 15 37 48 6.38 9.5 1.0 19.6 179.3 9.7 acidic
187 626634.6 5540329 4 11 21 69 5.90 13.9 1.5 10.4 62.3 8.1 acidic
188 622955.2 5516280 2 13 24 63 6.66 9.3 1.1 50.2 147.3 7.5 neutral
189 658950.5 5362713 8 21 31 48 7.05 18.9 2.0 59.0 226.6 15.1 neutral
190 656694.0 5382693 9 33 34 33 6.63 44.3 5.1 17.8 110.9 32.6 neutral
191 657081.0 5352686 9 21 51 28 7.48 24.4 2.1 16.0 108.7 19.5 neutral
192 651109.7 5350613 12 22 50 28 6.67 14.2 1.6 64.4 235.0 16.2 neutral
193 646828.4 5372566 4 13 26 61 6.05 10.3 1.3 60.9 224.0 17.9 acidic
194 644931.3 5364538 6 33 40 28 7.46 59.7 5.4 24.4 100.6 39.1 neutral
195 640727.4 5380492 9 21 32 47 7.38 49.3 4.9 62.3 117.1 29.6 neutral
196 638391.3 5406468 7 9 27 63 6.54 14.2 1.4 64.7 204.4 9.0 neutral
197 636573.8 5392446 47 20 44 37 8.08 40.3 1.9 59.6 162.5 18.7 alkaline
198 636891.3 5366442 4 11 24 65 6.50 10.5 1.3 59.9 198.2 7.6 acidic
199 634627.7 5388417 13 45 33 22 7.50 66.5 6.3 54.0 192.7 54.2 alkaline
200 635093.0 5352410 20 33 42 24 7.32 24.6 2.5 45.9 155.1 26.5 neutral
201 633302.5 5336385 10 21 72 7 6.61 9.2 1.1 30.0 157.4 8.9 neutral
202 633533.8 5318379 7 34 49 16 6.24 121.2 12.2 33.5 86.8 62.0 acidic
203 634042.9 5278365 12 29 41 30 6.35 37.5 3.9 0.0 85.4 20.8 acidic
204 631636.7 5310352 8 30 34 36 6.30 43.3 4.4 43.1 319.3 23.3 acidic
205 629996.9 5282319 4 27 56 17 7.12 55.8 5.7 21.8 119.8 31.7 neutral
206 627332.9 5334307 7 31 33 36 7.10 68.3 6.5 40.2 211.9 37.1 neutral
207 627794.9 5298297 29 28 44 28 7.04 69.4 6.5 67.5 217.0 33.1 neutral
208 623949.8 5286244 6 22 42 36 5.57 30.8 3.3 10.9 56.3 10.8 acidic
209 620167.6 5424238 7 43 31 26 7.82 20.1 2.2 23.6 710.4 28.2 alkaline
210 620404.2 5406237 12 36 50 14 7.19 32.3 3.3 19.1 173.9 30.8 neutral
211 620638.0 5388237 12 30 65 5 7.54 16.0 1.7 28.2 298.6 19.3 alkaline
212 621181.7 5346233 12 25 42 34 5.78 21.9 2.2 12.1 126.5 13.0 acidic
213 621413.6 5328231 7 23 31 46 5.66 32.9 2.7 14.9 42.1 12.9 acidic
214 618957.6 5362223 16 8 16 76 5.88 12.9 1.5 57.8 239.1 6.9 acidic
215 619620.3 5312201 15 25 61 14 6.39 22.1 2.3 12.8 182.3 12.9 acidic
216 619672.0 5308201 7 49 33 18 6.86 61.6 6.3 46.6 388.9 49.7 neutral
217 620082.2 5276192 24 28 52 20 7.17 55.8 5.7 31.6 74.8 28.2 neutral
218 617109.0 5352183 7 30 41 30 6.09 36.8 3.6 26.5 73.0 11.2 acidic
219 618032.4 5280167 21 14 53 32 6.54 42.0 4.1 0.0 72.0 22.5 neutral
220 614145.3 5426159 13 39 36 25 7.87 20.6 2.2 80.6 628.0 25.2 alkaline
221 614379.5 5408160 8 31 64 6 6.48 19.1 2.0 71.2 594.1 20.8 acidic
222 614615.6 5390161 1 31 58 11 6.04 24.4 2.3 13.2 123.8 18.6 acidic
223 614901.8 5368156 9 15 37 49 6.01 12.6 1.6 0.0 58.5 11.7 acidic
224 615032.0 5358161 6 30 52 17 6.22 21.6 2.4 39.4 121.1 17.8 acidic
225 615134.7 5350158 9 19 33 47 6.94 11.8 1.4 54.0 170.5 15.4 neutral
226 615265.6 5340157 4 16 33 51 5.65 24.2 2.7 12.6 73.3 8.6 acidic
227 613651.6 5310125 26 20 46 34 7.20 35.2 3.2 41.0 211.5 20.9 neutral
228 610771.0 5378107 14 26 46 29 7.67 61.1 5.4 46.4 126.6 54.6 alkaline
229 611781.2 5300099 29 19 54 27 7.28 59.4 5.1 35.9 194.7 34.0 neutral
230 609424.0 5328078 12 39 42 19 6.50 122.1 9.1 15.9 94.5 62.5 acidic
231 609887.2 5292070 10 17 51 32 7.16 55.0 5.3 45.6 239.2 28.9 neutral
232 607372.7 5332054 13 0 0 0 5.14 251.3 16.8 0.0 78.6 61.9 acidic
233 607786.2 5300048 6 25 46 29 5.85 37.8 4.0 24.3 93.6 15.0 acidic
234 606146.5 5272012 3 27 50 23 6.32 42.4 4.4 10.3 85.2 26.9 acidic
235 603582.9 5315999 10 30 34 36 6.30 35.7 3.5 18.7 178.1 22.6 acidic
236 603816.0 5297997 8 26 46 28 5.39 28.6 3.0 21.2 94.1 13.8 acidic
237 600973.9 5366005 9 22 55 23 7.10 18.2 1.9 61.8 495.1 17.3 neutral
238 601767.3 5301971 19 31 38 30 7.36 29.1 3.0 18.1 115.1 34.0 neutral
239 601997.0 5283966 26 30 43 27 6.45 90.7 8.1 44.5 134.5 47.8 acidic
240 599354.7 5333951 5 14 39 47 6.49 14.8 1.7 47.4 137.4 12.4 acidic
241 596628.3 5389928 4 18 28 54 7.95 14.7 1.5 30.7 275.8 15.0 alkaline
242 597382.0 5331926 8 23 50 28 6.46 26.1 2.7 33.6 387.6 15.2 acidic
243 597564.0 5317924 3 27 37 36 6.05 32.3 3.4 14.0 84.9 17.4 acidic
244 595668.8 5309896 4 35 33 32 5.95 38.8 3.9 37.3 231.0 23.6 acidic
245 596131.2 5273889 6 19 47 34 6.07 35.2 3.8 10.6 74.6 22.2 acidic
246 594082.5 5277863 21 20 46 34 7.38 37.8 3.2 0.0 71.4 25.9 neutral
247 591192.3 5345847 18 20 45 35 6.32 6.1 0.8 10.7 145.1 7.3 acidic
248 591826.2 5297843 4 25 41 34 5.54 28.7 3.1 0.0 75.8 13.6 acidic
249 588918.8 5367823 22 24 45 31 7.53 32.5 2.9 69.9 352.7 19.9 alkaline
250 589102.2 5353824 5 14 38 48 6.45 13.6 1.5 31.7 116.6 10.0 acidic
251 589802.7 5299817 9 21 34 45 5.53 29.4 2.8 41.0 196.4 12.6 acidic
252 590085.4 5277812 6 24 36 41 6.03 25.4 2.8 12.8 214.5 13.5 acidic
253 587467.5 5325796 11 15 60 25 6.08 11.2 1.3 64.0 200.6 9.7 acidic
254 587701.4 5307794 13 32 35 33 6.33 43.2 4.2 25.3 123.7 26.5 acidic
255 576980.3 5363668 14 33 47 20 7.47 22.6 2.7 29.3 336.1 27.4 neutral
256 574153.8 5273606 6 22 47 31 5.34 30.7 3.4 69.1 142.8 10.6 acidic
257 566189.3 5271503 16 26 42 32 5.67 49.1 4.8 27.2 95.2 18.8 acidic
258 560168.8 5273426 7 25 41 34 5.85 31.4 3.4 29.4 71.0 15.8 acidic
259 848381.1 5411014 23 11 28 62 6.36 17.8 1.3 12.2 46.0 7.1 acidic
260 840424.0 5406921 5 20 42 38 5.22 32.5 3.0 19.1 153.9 8.9 acidic
261 838498.1 5400889 38 4 27 69 4.73 27.3 1.4 36.8 88.7 4.4 acidic
262 830191.3 5424818 20 24 40 36 5.49 40.2 3.3 0.0 64.5 7.6 acidic
263 828515.6 5402761 7 12 27 61 5.27 17.9 1.5 80.9 145.3 8.7 acidic
264 826740.9 5380728 3 18 77 5 5.36 17.0 2.0 0.0 60.4 8.3 acidic
265 822412.6 5406711 20 8 15 76 5.79 21.9 2.2 28.5 145.2 7.0 acidic
266 822864.0 5370676 6 20 58 23 6.80 15.5 1.6 66.6 157.8 11.1 neutral
267 818233.3 5420675 11 18 37 45 5.67 26.9 2.5 28.9 64.0 7.4 acidic
268 816705.3 5382628 27 24 45 31 7.27 16.3 1.6 61.8 102.7 21.7 neutral
269 812859.8 5370547 13 12 38 50 6.08 14.9 1.8 65.4 246.8 8.8 acidic
270 812996.4 5360528 6 20 45 36 6.95 19.1 2.0 36.5 141.5 12.0 neutral
271 808400.9 5406547 5 21 73 6 6.38 23.6 2.5 28.1 386.7 10.0 acidic
272 804869.5 5370467 23 18 49 33 7.37 18.9 1.9 80.6 223.5 16.0 neutral
273 802478.3 5400470 5 13 36 51 7.55 33.1 1.8 54.2 145.7 12.9 alkaline
274 800660.1 5384422 4 18 47 35 7.00 10.8 1.3 40.4 276.1 10.3 neutral
275 801013.0 5366354 17 33 58 9 6.80 27.8 2.5 96.6 442.7 21.0 neutral
276 798245.9 5418439 8 15 29 56 4.37 32.4 3.1 16.4 62.4 4.5 acidic
277 798423.6 5404427 4 32 61 7 7.55 41.9 3.2 113.6 88.0 29.3 alkaline
278 798878.6 5368397 16 20 47 33 5.43 27.7 2.8 12.0 53.5 10.8 acidic
279 796373.0 5408407 11 18 41 42 7.55 28.8 2.2 39.8 129.3 15.7 alkaline
280 794550.6 5396423 11 24 70 6 7.94 9.0 1.0 45.2 119.2 16.8 alkaline
281 794750.8 5378335 7 17 53 30 5.78 12.5 1.4 49.7 210.4 6.7 acidic
282 784293.6 5414267 11 18 76 6 7.27 10.5 1.3 66.9 352.4 11.2 neutral
283 784909.1 5364222 14 20 53 27 5.63 17.3 1.8 15.5 91.9 9.1 acidic
284 778369.1 5408191 16 19 68 13 7.78 18.1 1.6 101.2 375.1 15.3 alkaline
285 774212.3 5420157 16 16 42 42 7.63 15.1 1.7 103.9 378.8 14.7 alkaline
286 774622.5 5384144 32 20 64 16 6.23 16.3 1.8 29.4 118.8 10.4 acidic
287 774899.2 5366121 16 16 56 27 6.40 16.2 1.7 54.3 241.1 10.7 acidic
288 772025.9 5434135 6 16 43 41 5.83 15.3 1.4 91.2 206.0 10.5 acidic
289 772505.3 5392106 9 29 54 17 7.90 21.2 1.9 50.9 381.3 22.9 alkaline
290 772850.0 5370093 13 15 36 49 5.71 13.0 1.5 15.8 65.1 8.0 acidic
291 770440.8 5402094 23 23 59 18 7.81 17.1 1.5 67.8 283.4 17.6 alkaline
292 770567.5 5390130 29 24 48 28 7.03 13.8 1.5 88.3 274.0 17.6 neutral
293 768578.6 5406123 13 30 62 8 7.68 17.7 1.9 89.2 313.7 22.7 alkaline
294 768797.3 5374050 21 32 47 21 6.55 20.2 2.1 64.8 321.1 22.3 neutral
295 760132.9 5425983 8 9 21 70 7.36 12.4 1.3 67.8 150.7 7.8 neutral
296 758157.4 5423962 4 14 61 25 7.38 45.1 3.1 15.9 56.8 21.6 neutral
297 758515.3 5395946 28 37 47 16 7.23 148.1 11.2 52.6 260.9 83.7 neutral
298 754333.2 5409896 6 19 61 20 6.94 13.5 1.4 78.7 384.1 12.2 neutral
299 754614.6 5387893 10 17 73 10 6.93 15.0 1.7 50.6 285.4 13.6 neutral
300 744998.1 5357759 8 18 40 42 7.17 21.3 2.2 68.9 64.1 18.1 neutral
301 740384.7 5405734 2 26 61 14 7.26 16.5 1.7 54.0 314.0 2.7 neutral
302 738436.8 5401710 8 29 60 10 7.37 18.9 1.9 42.3 235.3 18.9 neutral
303 736615.8 5387675 8 24 61 15 7.83 35.1 3.2 33.0 0.0 32.7 alkaline
304 734362.7 5407662 7 33 39 27 5.62 17.4 1.8 42.0 255.7 21.5 acidic
305 732822.5 5369684 2 30 46 24 6.61 11.9 1.4 38.2 202.9 16.1 neutral
306 728437.5 5401587 21 26 51 23 6.96 19.3 2.1 78.2 353.2 18.4 neutral
307 728593.1 5389584 26 26 64 10 7.77 14.8 1.7 73.5 344.9 18.3 alkaline
308 724132.0 5425551 17 29 31 40 7.09 12.9 1.5 50.2 16.6 17.6 neutral
309 720668.9 5383481 15 26 48 26 7.53 11.0 1.4 35.9 198.1 19.0 alkaline
310 718258.2 5415470 5 27 61 13 7.74 14.5 1.4 72.6 334.2 18.2 alkaline
311 714389.3 5405419 2 24 61 15 7.65 13.8 1.5 57.3 218.9 19.0 alkaline
312 714567.8 5391413 8 21 64 15 7.56 17.6 1.8 90.8 231.9 17.4 alkaline
313 710259.3 5415358 9 22 40 38 7.51 10.9 1.2 67.5 203.5 15.1 alkaline
314 679435.2 5479005 35 27 60 13 6.25 25.2 2.5 10.3 0.0 14.3 acidic
315 667413.9 5480857 13 41 29 30 5.73 44.0 4.2 17.5 133.2 26.1 acidic
316 667830.4 5448853 3 32 27 41 7.21 22.0 2.1 64.5 583.4 22.2 neutral
317 661991.6 5436765 11 36 56 8 7.15 18.7 2.0 83.7 614.5 21.1 neutral
318 655285.1 5490700 6 4 9 86 5.63 7.8 0.7 45.7 82.7 5.1 acidic
319 655914.0 5442699 17 25 58 17 7.01 13.6 1.4 28.1 183.2 12.5 neutral
320 649942.5 5440626 6 38 48 14 6.40 26.3 2.7 37.4 257.7 21.5 acidic
321 644155.2 5424548 6 22 68 10 5.92 16.3 1.7 55.8 191.1 10.4 acidic
322 640078.4 5430493 6 49 45 6 7.72 19.8 2.1 0.0 264.4 24.0 alkaline
323 637333.6 5486472 4 17 41 42 6.92 13.8 1.3 54.1 265.3 9.9 neutral
324 637448.9 5478465 8 18 28 53 6.39 19.3 2.0 21.2 47.7 11.2 acidic
325 638188.8 5424477 12 27 68 5 5.86 19.2 2.2 21.6 80.6 13.6 acidic
326 635792.1 5452444 8 10 26 64 5.36 9.4 0.8 95.6 116.5 2.9 acidic
327 631951.7 5440391 12 43 30 27 7.41 26.8 2.4 34.3 346.0 21.5 neutral
328 629056.9 5508361 3 24 47 29 6.71 11.0 1.2 16.1 246.6 11.7 neutral
329 630005.1 5436366 17 30 53 17 5.90 16.7 1.9 15.6 146.0 14.2 acidic
330 627666.1 5462337 8 18 36 46 6.68 34.6 3.5 45.7 106.0 21.9 neutral
331 625455.2 5478313 13 25 25 51 6.91 38.1 3.7 24.1 148.7 24.5 neutral
332 625535.5 5472313 3 9 24 67 7.14 13.6 1.7 63.8 388.3 9.4 neutral
333 625771.4 5454315 7 11 26 63 7.49 6.0 0.7 60.5 198.0 9.0 neutral
334 626008.8 5436316 6 41 48 11 6.50 30.8 2.9 0.0 156.4 24.9 acidic
335 617326.8 5488205 6 22 22 56 6.01 13.8 1.4 28.3 126.7 10.4 acidic
336 615225.9 5496179 13 31 34 36 7.45 28.0 2.9 27.6 133.5 23.9 neutral
337 611225.1 5496124 8 9 24 68 7.60 11.7 1.4 101.4 232.3 12.3 alkaline
338 607545.4 5472076 5 13 37 50 6.24 12.5 1.5 64.9 308.4 9.2 acidic
339 605729.7 5458054 12 74 23 3 6.50 53.3 5.9 0.0 269.8 54.8 acidic
340 599414.6 5481971 26 42 53 5 7.12 45.2 4.5 28.0 258.2 37.6 neutral
341 599577.1 5469973 13 23 35 42 7.05 14.5 1.5 32.9 263.9 13.7 neutral
342 595869.6 5447893 3 20 45 35 7.46 10.1 1.1 19.3 120.8 13.0 neutral
343 591368.8 5485864 3 19 74 7 7.91 11.4 1.4 26.3 161.7 16.0 alkaline
344 585398.3 5483786 12 34 47 18 7.73 16.8 1.8 46.6 328.1 22.8 alkaline
345 583374.3 5485761 12 38 58 4 7.50 37.3 3.5 13.3 185.8 40.7 alkaline
346 581586.1 5469739 0 36 53 11 7.30 29.4 3.0 15.2 527.2 24.8 neutral

3.1 Visualization with plots

The R Graph Gallery

# We separate only two properties to make easier to work with them
pH <- soil_data$pH
OC <- soil_data$OC
N <- soil_data$N

# We also create a data.frame with those 3 variables (only for easy handling)
data <- as.data.frame(cbind(pH, OC, N))

3.1.1 Boxplots boxplot()

boxplot(pH, N, names = c("pH value", "N [%]"), ylab = "pH in water and N")

  • Data to be displayed: pH and Corg.
  • Labeling of the x-axis: names = c("pH value", "N [%]").
  • Labeling of the y-axis: ylab = "pH in water and N".

What does the boxplot show?

3.1.2 Histograms hist()

hist(pH,
     xlab = "pH value", 
     ylab = "Frequency", 
     main = ""
     )

3.1.3 Density plots plot(density())

plot(density(pH),
     xlab = "pH value",
     ylab = "Frequency", 
     main = ""
     )

3.1.4 Scatterplots plot(x, y)

plot(N, 
     OC, 
     xlab = "OC [%]",
     ylab = "N [%]"
     )

3.1.5 Design options

Directly in the graphic routines (help with ?par)

  • Set colors with col = ...
  • Set symbol properties with pch = ..., sizes with cex = ...
  • Set title with main = ..., axis label with xlab = ..., ylab = ...
  • Set drawing area with xlim = ..., ylim = ...

After drawing a graphic

  • Complete lines and points with lines(...) or points(...) respectively.
  • Add captions (texts) with text(...) or mtext(...)
  • Complete titles with title(...)
  • Complete legend with legend(...)

Output adjustment

  • main Title of the diagram
  • xlab labeling of the x-axis
  • ylab labeling of the y-axis
  • breaks frequency classes number of bars
  • col color filling of the bars
  • cex gradual scaling of text size
hist(pH, 
     xlab = "pH value", 
     ylab = "Frequency", 
     main = "",
     breaks = seq(3.5, 8.5, 0.125), 
     col = "red",
     cex = 0.5
     )

3.2 All roads lead to Rome

When working with code, it is very common that there are several ways to solve the same problem.

Exercise:

  • Create boxplots and histograms for clay content and P.

  • Create a density of CEC distribution.

  • Plot the correlations between clay content and OC.

  • And now for the frequency distribution of pH_class, create one of the next plots.

In the variable pH_class, pH is classified as:

  • neutral: 6.5 to 7.5
  • alkaline: over 7.5
  • acidic: less than 6.5

Hint: The three different version are made with a barplot(), plot() and hist()

You do need to remember the importance of factors transformation.

3.2.1 Variant A

3.2.2 Variant B

3.2.3 Variant C

3.2.3.1 Solution

See solution
# Variant A
barplot(pH_class_count$Freq, space = 0, names = pH_class_count$Var1, 
                    xlab = "pH class", ylab = "Frequency", 
                    main = "Frequency diagram of pH classes") 

# Variant B
plot(factor(soil_data$pH_class), 
     xlab = "pH class", 
     ylab = "Frequency", 
     main = "Frequency diagram of pH classes")

# Variant C
hist(as.numeric(factor(soil_data$pH_class)),
     breaks = c(0, 1, 2, 3),
     freq = TRUE,
     xaxt = "n",
     xlab = "pH class",
     ylab = "Frequency",
     main = "Frequency diagram of pH classes")

axis(side = 1, at = seq(0.5, 2.5, 1), labels = c("acidic", "alkaline", "neutral"))

3.3 Multiple plots in one figure

When you set graphical parameters in Rstudio using this method, it is important to set the properties, plot the figures and reset the properties to the way they were before. Otherwise, every time we plot something, it will follow the set parameters.

par(                              # set or query graphical parameters
  mfrow = c(1, 3),                # 1 x 3 pictures on one plot, equivalent to mfcol = c(3, 1)
  mar = c(5.1, 4.1, 4.1, 2.1),    # margins as c(bottom, left, top, right)
  oma = c(0, 0, 0, 0),            # outer margins in lines of text as c(bottom, left, top, right)
  mgp = c(3, .1, 0),              # margins line for axis title, axis label and axis line
  las = 0,                        # label axis style 
  cex.lab = 1,                    # size of the labels
  cex.axis = 1,                   # size of the axis annotation 
  xpd = FALSE                     # If FALSE, all plotting is clipped to the plot region, if TRUE, all plotting is clipped to the figure region, and if NA, all plotting is clipped to the device region.
    )
dev.off()                         # reset the original parameters

plot(…); plot(…); plot(…)

par(mfrow = c(1, 1), 
    mar = c(5.1, 4.1, 4.1, 2.1), 
    oma = c(0, 0, 0, 0), 
    mgp = c(3, 1, 0), 
    las = 0, 
    cex.lab = 1, 
    cex.axis = 1,
    )

3.4 Plots file output

In R it is possible to export images in the most common formats. The output format must be specified and the file will be generated by default in our working directory.

tiff("filename.jpg", width = 21, height = 8, units = "cm", res = 300)

par(…)
    plot(…); plot(…); plot(…)
par(…)

dev.off()

Plot export can be done in most of the image formats. E.g. .png, .jpg, .svg, .pdf.