data( cars )
dim(cars)
## [1] 50 2
summary( cars )
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
cars
## speed dist
## 1 4 2
## 2 4 10
## 3 7 4
## 4 7 22
## 5 8 16
## 6 9 10
## 7 10 18
## 8 10 26
## 9 10 34
## 10 11 17
## 11 11 28
## 12 12 14
## 13 12 20
## 14 12 24
## 15 12 28
## 16 13 26
## 17 13 34
## 18 13 34
## 19 13 46
## 20 14 26
## 21 14 36
## 22 14 60
## 23 14 80
## 24 15 20
## 25 15 26
## 26 15 54
## 27 16 32
## 28 16 40
## 29 17 32
## 30 17 40
## 31 17 50
## 32 18 42
## 33 18 56
## 34 18 76
## 35 18 84
## 36 19 36
## 37 19 46
## 38 19 68
## 39 20 32
## 40 20 48
## 41 20 52
## 42 20 56
## 43 20 64
## 44 22 66
## 45 23 54
## 46 24 70
## 47 24 92
## 48 24 93
## 49 24 120
## 50 25 85
head( cars )
## speed dist
## 1 4 2
## 2 4 10
## 3 7 4
## 4 7 22
## 5 8 16
## 6 9 10
tail( cars )
## speed dist
## 45 23 54
## 46 24 70
## 47 24 92
## 48 24 93
## 49 24 120
## 50 25 85
str( cars )
## 'data.frame': 50 obs. of 2 variables:
## $ speed: num 4 4 7 7 8 9 10 10 10 11 ...
## $ dist : num 2 10 4 22 16 10 18 26 34 17 ...
plot ( cars )
###################################### # # 繪圖視窗之設定 # # pointsize: 文字或符號字體大小
windows( width = 4.5, height = 3.3, pointsize = 8 )
par( mex = 0.8, mar = c(5, 5, 4, 2) + 0.1 )
old.par <- par( mex = 0.9, mar = c(5, 5, 4, 2) + 0.1 )
plot ( cars )
# reset to previous settings
par( old.par ) # reset to previous settings
win.graph( width = 4.5, height = 3.3, pointsize = 8 )
old.par <- par( mex = 0.8, mar = c(5, 5, 4, 2) + 0.1 )
plot( cars )
par( old.par ) # reset to previous settings
plot( cars, xlim = c(0, 30), ylim = c(0, 130), xlab = "xlab", ylab = "ylab", main = "main title", sub = "subtitle", cex = 0.8, pch = 16, col = "red")
plot( 1:25, pch = 0:25, col = 1:8, xlab = "number", ylab = "" )
plot( 0:10, 0:10, col = 1:10, pch = 16, xlab = "X axis", ylab = "Y axis", axes = FALSE )
plot( 0:10, 0:10, col = 1:10, pch = 16, xlab = "X axis", ylab = "Y axis", axes = FALSE )
axis( side = 1, col = "black", col.axis = "red", at = 0:10, label = LETTERS[1:11] )
plot( 0:10, 0:10, col = 1:10, pch = 16, xlab = "X axis", ylab = "Y axis", axes = FALSE )
axis( side = 2, col = "green", col.axis = "blue", at = seq(from = 0, to = 10, by = 1) )
plot( 0:10, 0:10, col = 1:10, pch = 16, xlab = "X axis", ylab = "Y axis", axes = FALSE )
axis( side = 3, col = "cyan", col.axis = "magenta", at = seq(from = 0, to = 8, by = 1) )
plot( 0:10, 0:10, col = 1:10, pch = 16, xlab = "X axis", ylab = "Y axis", axes = FALSE )
axis( side = 4, col = "yellow", col.axis = "gray", at = seq(from = 2, to = 10, by = 2), label = c(20, 40, 60, 80, 100) )
plot( cars, xlab = "", ylab = "" )
title( main = "cars data", xlab = "speed", ylab = "distance" )
text( 20, 100, label = "text here" )
legend( "topleft", legend = c("x: speed", "y: distance") )
mtext( text = c("Bottom", "Left", "Top", "Right"), side = 1:4, col = 1:4, line = -2 )
# line = -2: 往內移動兩個線寬度
plot( cars, xlab = "", ylab = "" )
title( main = "cars data", xlab = "speed", ylab = "distance" )
text( 20, 100, label = "text here" )
# legend( locator(1), legend = c("x: speed", "y: distance") )
# on Console Windows #
mtext( text = c("Bottom", "Left", "Top", "Right"), side = 1:4, col = 1:4, line = -2 )
plot(0:10, 0:10, xlab = "", ylab = "", pch = 1:10, col = 1:10)
text( 2, 8, label = expression( chi^2 == "4.4" ) )
text( 2, 7, label = expression( x[3] == "5.5" ) )
text( 2, 6, label = expression( y[3]^2 == "8.8" ) )
text( 8, 5, label = expression( hat(y) %+-% z ) )
plot(0:10, 0:10, xlab = "", ylab = "", pch = 1:10, col = 1:10)
label.eq <- expression( paste( "f(x) = ", frac(1, sigma*sqrt(2 * pi)), " ", e^{frac(-(x - mu)^2, 2*sigma^2)} ) )
text( 7, 2, label = label.eq )
x <- seq( from = -4, to = 4, length = 101 )
xlab <- expression( paste( "phase angle ", phi ) )
ylab <- expression( paste( "cos(", phi, ")" ) )
plot( x, cos(x), type = "l", xaxt = "n", xlab = xlab, ylab = ylab )
label <- expression( -pi, -pi / 2, 0, pi / 2, pi )
axis( side = 1, at = c(-pi, -pi / 2, 0, pi / 2, pi), label = label )
# ?plotmath
# demo( plotmath )
# on Console Windows #
# demo( Hershey )
# on Console Windows #