Dual x và dual y trong base R graphics | www.tuhocr.com

vietnam_rice <- read.csv("vietnam_rice.csv")
vietnam_rice
##        area item year production area_harvested yield
## 1  Viet Nam Rice 2021   43852729        7219797  6.07
## 2  Viet Nam Rice 2020   42765000        7222403  5.92
## 3  Viet Nam Rice 2019   43495488        7451544  5.84
## 4  Viet Nam Rice 2018   44046250        7570741  5.82
## 5  Viet Nam Rice 2017   42763682        7708534  5.55
## 6  Viet Nam Rice 2016   43112010        7734722  5.57
## 7  Viet Nam Rice 2015   45090562        7828607  5.76
## 8  Viet Nam Rice 2014   44974206        7816476  5.75
## 9  Viet Nam Rice 2013   44039100        7902813  5.57
## 10 Viet Nam Rice 2012   43737598        7761314  5.64
## 11 Viet Nam Rice 2011   42398344        7655440  5.54
## 12 Viet Nam Rice 2010   40005600        7489400  5.34
## 13 Viet Nam Rice 2009   38950200        7437200  5.24
## 14 Viet Nam Rice 2008   38729800        7400200  5.23
## 15 Viet Nam Rice 2007   35942700        7207400  4.99
## 16 Viet Nam Rice 2006   35849500        7324800  4.89
## 17 Viet Nam Rice 2005   35832900        7329200  4.89
## 18 Viet Nam Rice 2004   36148900        7445300  4.86
## 19 Viet Nam Rice 2003   34568800        7452200  4.64
## 20 Viet Nam Rice 2002   34447200        7504300  4.59
## 21 Viet Nam Rice 2001   32108400        7492700  4.29
## 22 Viet Nam Rice 2000   32529500        7666300  4.24
## 23 Viet Nam Rice 1999   31393800        7653600  4.10
## 24 Viet Nam Rice 1998   29408143        7350801  4.00
## 25 Viet Nam Rice 1997   27523900        7099700  3.88
## 26 Viet Nam Rice 1996   26396700        7003800  3.77
## 27 Viet Nam Rice 1995   24963700        6765600  3.69
## 28 Viet Nam Rice 1994   23528300        6598600  3.57
## 29 Viet Nam Rice 1993   22836600        6559400  3.48
## 30 Viet Nam Rice 1992   21590304        6475400  3.33
## 31 Viet Nam Rice 1991   19621904        6302700  3.11
## 32 Viet Nam Rice 1990   19225104        6042800  3.18
## 33 Viet Nam Rice 1989   18996304        5911200  3.21
## 34 Viet Nam Rice 1988   17000000        5740800  2.96
## 35 Viet Nam Rice 1987   15102600        5603100  2.70
## 36 Viet Nam Rice 1986   16002900        5703100  2.81
## 37 Viet Nam Rice 1985   15874800        5718300  2.78
## 38 Viet Nam Rice 1984   15505600        5675000  2.73
## 39 Viet Nam Rice 1983   14743300        5611700  2.63
## 40 Viet Nam Rice 1982   14390200        5711700  2.52
## 41 Viet Nam Rice 1981   12415200        5651900  2.20
## 42 Viet Nam Rice 1980   11647400        5600200  2.08
## 43 Viet Nam Rice 1979   11362900        5485200  2.07
## 44 Viet Nam Rice 1978    9789900        5462500  1.79
## 45 Viet Nam Rice 1977   10597100        5468700  1.94
## 46 Viet Nam Rice 1976   11827200        5297300  2.23
## 47 Viet Nam Rice 1975   10293600        4855900  2.12
## 48 Viet Nam Rice 1974   11023290        5111920  2.16
## 49 Viet Nam Rice 1973   11125000        5030000  2.21
## 50 Viet Nam Rice 1972   10748200        4900000  2.19
## 51 Viet Nam Rice 1971   10447000        4692100  2.23
## 52 Viet Nam Rice 1970   10173300        4724400  2.15
## 53 Viet Nam Rice 1969    8815000        4930000  1.79
## 54 Viet Nam Rice 1968    8366150        4893800  1.71
## 55 Viet Nam Rice 1967    9188400        4795800  1.92
## 56 Viet Nam Rice 1966    8463500        4681300  1.81
## 57 Viet Nam Rice 1965    9369700        4826300  1.94
## 58 Viet Nam Rice 1964    9697030        4987800  1.94
## 59 Viet Nam Rice 1963    9622670        4496520  2.14
## 60 Viet Nam Rice 1962    9747040        4888860  1.99
## 61 Viet Nam Rice 1961    8997400        4744000  1.90
vietnam_rice$production/1000000 -> rice_production

vietnam_rice$area_harvested/1000000 -> rice_area

par(pty = "s")

par(mar = c(10, 10, 5, 2))

par(mgp = c(8, 1, 0))

plot(rice_production ~ rice_area,
     xaxs = "i", yaxs = "i",
     xlim = c(4, 9), ylim = c(0, 50),
     xlab = "Diện tích canh tác (triệu ha)",
     ylab = "Sản lượng thu hoạch (triệu tấn)",
     xaxt = "n",
     yaxt = "n",
     pch = 19,
     col = "blue")

title(main = "Tương quan giữa diện tích canh tác và sản lượng thu hoạch",
      col.main = "darkgreen", 
      line = 1.5,
      cex = 0.5)

axis(side = 1,
     at = c(4, 5, 6, 7, 8, 9))

axis(side = 1,
     at = c(4, 5, 6, 7, 8, 9),
     labels = c("", "Nhỏ", "Trung bình", "Lớn", "Rất lớn", ""),
     line = 3)

axis(side = 2,
     at = c(0, 10, 20, 30, 40, 50), las = 2)

axis(side = 2,
     at = c(0, 10, 20, 30, 40, 50), las = 2,
     labels = c("", "Nhỏ", "Trung bình", "Lớn", "Rất lớn", ""),
     line = 3)

## Chèn đường trend line
abline(lm(rice_production ~ rice_area), col = 2, lwd = 2)