par( mfrow = c(2, 2), mex = 0.8, mar = c(5, 5, 4, 2) + 0.1 )
par( mfcol = c(2, 2), mex = 0.8, mar = c(5, 5, 4, 2) + 0.1 )
plot( cars, main = "cars data", cex = 2 )
plot( cars, main = "cars data", cex.axis = 2 )
plot( cars, main = "cars data", cex.lab = 2 )
plot ( cars, main = "cars data", cex.main = 2 )
plot( cars, main = "las = 0", las = 0 )
# 0: always parallel to the axis [default]
plot( cars, main = "las = 1", las = 1 )
# 1: always horizontal
plot( cars, main = "las = 2", las = 2 )
# 2: always perpendicular to the axis
plot( cars, main = "las = 3", las = 3 )
# 3: always vertical
plot( cars, main = "las = 0", las = 0 ) # 0: always parallel to the axis [default]
plot( cars, main = "las = 1", las = 1 ) # 1: always horizontal
plot( cars, main = "las = 2", las = 2 ) # 2: always perpendicular to the axis
plot( cars, main = "las = 3", las = 3 ) # 3: always vertical
par( mfrow = c(2, 3), mex = 0.6, mar = c(5, 4, 4, 2) + 0.1 )
plot( cars, type = "p", main = "type = p" ) # "p" for points
plot( cars, type = "l", main = "type = l" ) # "l" for lines
plot( cars, type = "b", main = "type = b" ) # "b" for both
plot( cars, type = "o", main = "type = o" ) # "o" for both ‘overplotted’
plot( cars, type = "h", main = "type = h" ) # "h" for histogram-like vertical lines
plot( cars, type = "n", main = "type = n" ) # "n" for no plotting
plot( cars, type = "p", main = "type = p" ) # "p" for points
plot( cars, type = "l", main = "type = l" ) # "l" for lines
plot( cars, type = "b", main = "type = b" ) # "b" for both
plot( cars, type = "o", main = "type = o" ) # "o" for both ‘overplotted’
plot( cars, type = "h", main = "type = h" ) # "h" for histogram-like vertical lines
plot( cars, type = "n", main = "type = n" ) # "n" for no plotting
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
# matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T )
plot( iris[ , 1 ] )
plot( iris[ , 2 ] )
plot( iris[ , 3 ] )
plot( iris[ , 4 ] )
# 幾張圖繪製在一起
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
hist( iris[ , 1 ] )
hist( iris[ , 2 ] )
hist( iris[ , 3 ] )
hist( iris[ , 4 ] )
layout( matrix( c( 1, 2, 3, 4, 5, 6, 7, 8) , 4, 2, byrow = T ), widths = c(1,1), heights = c(1,1,1,1) )
layout( matrix( c( 1, 2, 3, 4, 5, 6, 7, 8) , 2, 4, byrow = F ), widths = c(1,1), heights = c(1,1,1,1) )
# matrix( c( 1, 2, 3, 4, 5, 6, 7, 8) , 4, 2, byrow = T )
# heights = c(1,1,1,1)
plot( iris[ , 1 ] )
hist( iris[ , 1 ] )
plot( iris[ , 2 ] )
hist( iris[ , 2 ] )
plot( iris[ , 3 ] )
hist( iris[ , 3 ] )
plot( iris[ , 4 ] )
hist( iris[ , 4 ] )
layout( matrix( c( 1, 2, 3, 4 ) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
layout( matrix( c( 1, 2, 3, 4, 5, 6, 7, 8) , 4, 2, byrow = T ), widths = c(1,2), heights = c(1,1,1,1) )
# widths = c(1,2)
layout( matrix( c( 1, 2, 3, 4 ) , 2, 2, byrow = T ), widths = c(1,2), heights = c(1,1) )
layout( matrix( c( 1, 2, 3, 4 ) , 2, 2, byrow = F ), widths = c(1,1), heights = c(2,1) )
plot( iris[ , 1 ] )
hist( iris[ , 1 ] )
plot( iris[ , 2 ] )
hist( iris[ , 2 ] )
plot( iris[ , 3 ] )
hist( iris[ , 3 ] )
plot( iris[ , 4 ] )
hist( iris[ , 4 ] )
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(2,1), heights = c(1,1) )
# widths = c(2,1)
plot( iris[ , 1 ] )
hist( iris[ , 1 ] )
plot( iris[ , 2 ] )
hist( iris[ , 2 ] )
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,1), heights = c(2,1) )
# heights = c(2,1)
plot( iris[ , 1 ] )
hist( iris[ , 1 ] )
plot( iris[ , 2 ] )
hist( iris[ , 2 ] )
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,3), heights = c(1,1) )
# widths = c(1,3)
plot( iris[ , 1 ] )
hist( iris[ , 1 ] )
plot( iris[ , 2 ] )
hist( iris[ , 2 ] )
# figure margins too large
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
# widths = c(1,3), heights = c(1,3)
plot( iris[ , 1 ] )
hist( iris[ , 1 ] )
plot( iris[ , 2 ] )
hist( iris[ , 2 ] )
layout( matrix( c( 1, 2, 3, 0) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
# c( 1, 2, 3, 0)
plot( iris[ , 1 ] )
plot( iris[ , 2 ] )
plot( iris[ , 3 ] )
layout( matrix( c( 1, 0, 2, 3) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
# c( 1, 0, 2, 3)
plot( iris[ , 1 ] )
plot( iris[ , 2 ] )
plot( iris[ , 3 ] )
layout( matrix( c( 1, 0, 0, 2) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
# c( 1, 0, 0, 2)
plot( iris[ , 1 ] )
plot( iris[ , 2 ] )
# on Console Windows
windows()
layout( matrix( c( 1 ) , 1, 1, byrow = T ), widths = c(1), heights = c(1) )
par( fig=c( 0, 0.4, 0, 0.6 ), new=TRUE )
## Warning in par(fig = c(0, 0.4, 0, 0.6), new = TRUE): calling par(new=TRUE) with
## no plot
plot( iris[ , 1 ] )
par( fig=c( 0, 0.4, 0.6, 1 ), new=TRUE )
plot( iris[ , 2 ] )
par( fig=c( 0.2, 1, 0.1, 0.5 ), new=TRUE )
plot( iris[ , 3 ] )
par( fig=c( 0.3, 1, 0.3, 1 ), new=TRUE )
plot( iris[ , 4 ] )
# on Console Windows
layout( matrix( 1:4, nrow = 2 ) )
# 2x2 的圖形矩陣,依照指定的位置
layout( matrix( c(1, 2, 1, 3), nrow = 2, ncol = 2 ) )
layout( matrix( c(1, 2, 0, 3), nrow = 2, ncol = 2), width = c(2, 1), height = c(1, 1.5) )
layout( matrix( 1:4, nrow = 2) )
# 1:4
plot( cars, las = 0, main = "las = 0" )
plot( cars, las = 1, main = "las = 1" )
plot( cars, las = 2, main = "las = 2" )
plot( cars, las = 3, main = "las = 3" )
layout(1)
# re-set as 1x1
layout( matrix( c(1, 2, 1, 3), nrow = 2, ncol = 2) )
# c(1, 2, 1, 3)
plot( cars, las = 1, main = "las = 1" )
plot( cars, las = 2, main = "las = 2" )
plot( cars, las = 3, main = "las = 3" )
layout(1)
# re-set as 1x1
layout( matrix( c(1, 2, 0, 3), nrow = 2, ncol = 2), width = c(2, 1), height = c(1, 1.5))
# c(1, 2, 0, 3)
plot( cars, las = 1, main = "las = 1" )
plot( cars, las = 2, main = "las = 2" )
plot( cars, las = 3, main = "las = 3" )
layout(1)
# re-set as 1x1
# data
x <- c( 2, 3, 4 )
y <- c( 6, 7, 8 )
# widows setting
par( mex = 0.8, mar = c(5, 4, 4, 2) + 0.1 )
# plot data
plot( 0:10, 0:10, xlab = "", ylab = "", pch = 1:11, col = 1:8, axes = FALSE )
# plot data
plot( 0:10, 0:10, xlab = "", ylab = "", pch = 1:11, col = 1:8, axes = FALSE )
# axis
axis( side = 1, at = 0:10 )
axis( side = 2, at = 0:10 )
box()
# plot data
plot( 0:10, 0:10, xlab = "", ylab = "", pch = 1:11, col = 1:8, axes = FALSE )
# axis
axis( side = 1, at = 0:10 )
axis( side = 2, at = 0:10 )
box()
# add lines
lines( c(1, 2), c(9, 10), col = "yellow", lwd = 3 )
abline( a = -2, b = 1, col = "gold", lwd = 2 )
abline( a = 3, b = 1, col = "red", lwd = 6 )
abline( a = 9, b = -1, col = "blue", lwd = 20 )
# widows setting
par( mex = 0.8, mar = c(5, 4, 4, 2) + 0.1 )
# plot data
plot( 0:10, 0:10, xlab = "", ylab = "", pch = 1:11, col = 1:8, axes = FALSE )
# axis
axis( side = 1, at = 0:10 )
axis( side = 2, at = 0:10 )
box()
# add lines
lines( c(1, 2), c(9, 10), col = "yellow", lwd = 3 )
abline( a = -2, b = 1, col = "gold", lwd = 2 )
abline( a = 3, b = 1, col = "red", lwd = 6 )
abline( a = 9, b = -1, col = "blue", lwd = 20 )
# horizontal line
abline( h = 1:3, lty = 1:3, lwd = c(1.0, 1.5, 2.0), col = c("red", "green", "blue") )
# vertical lines
abline( v = 6:8, lty = 1:3, lwd = c(1.0, 1.5, 2.0), col = c("red", "green", "blue") )
# widows setting
par( mex = 0.8, mar = c(5, 4, 4, 2) + 0.1 )
# plot data
plot( 0:10, 0:10, xlab = "", ylab = "", pch = 1:11, col = 1:8, axes = FALSE )
# axis
axis( side = 1, at = 0:10 )
axis( side = 2, at = 0:10 )
box()
# add lines
lines( c(1, 2), c(9, 10), col = "yellow", lwd = 3 )
abline( a = -2, b = 1, col = "gold", lwd = 2 )
abline( a = 3, b = 1, col = "red", lwd = 6 )
abline( a = 9, b = -1, col = "blue", lwd = 20 )
# horizontal line
abline( h = 1:3, lty = 1:3, lwd = c(1.0, 1.5, 2.0), col = c("red", "green", "blue") )
# vertical lines
abline( v = 6:8, lty = 1:3, lwd = c(1.0, 1.5, 2.0), col = c("red", "green", "blue") )
# add points
points( x, y, col = "violet", pch = 16, cex = 2 )
points( x+1, y-1, col = "green", pch = 10, cex = 5 )
# add segments
segments( x[1], y[1], x[2], y[2], col = "violet", lwd = 2)
segments( x[2], y[2], x[3], y[3], col = "dark violet", lwd = 2 )
# add arrows
arrows( 1, 7, 1, 8, code = 1, length = 0.1, col = "pink", lwd = 2 )
arrows( 2, 8, 3, 9, code = 2, length = 0.1, col = "pink", lwd = 2 )
x <- seq(from = -pi, to = pi, length = 101)
y1 <- sin(x)
y2 <- cos(x)
y3 <- sin(x) + cos(x)
ylim <- range(y1, y2, y3)
par( mex = 0.8, mar = c(5, 4, 3, 1) + 0.1 )
plot( x, y1, xlim = range(x), ylim = ylim, type = "n", xaxt = "n", xlab = "x", ylab = "", main = "Using matpoints()" )
#
label <- expression( -pi, -pi / 2, 0, pi / 2, pi )
axis( side = 1, at = c(-pi, -pi / 2, 0, pi / 2, pi), label = label )
#####
par( mex = 0.8, mar = c(5, 4, 3, 1) + 0.1 )
plot( x, y1, xlim = range(x), ylim = ylim, type = "n", xaxt = "n", xlab = "x", ylab = "", main = "Using matpoints()" )
#
label <- expression( -pi, -pi / 2, 0, pi / 2, pi )
axis( side = 1, at = c(-pi, -pi / 2, 0, pi / 2, pi), label = label )
#####
matpoints( x, cbind(y1, y2, y3), type = "l", col = c("red", "green", "blue"), lty = 1:3, lwd = 1:3 )
legend( "topleft", legend = c("y1", "y2", "y3"), col = c("red", "green", "blue"), lty = 1:3, lwd = 1:3 )
###
par( mex = 0.8, mar = c(5, 4, 3, 1) + 0.1 )
plot( x, y1, xlim = range(x), ylim = ylim, type = "n", xaxt = "n", xlab = "x", ylab = "", main = "Using matlines()" )
label <- expression( -pi, -pi / 2, 0, pi / 2, pi )
axis( side = 1, at = c(-pi, -pi / 2, 0, pi / 2, pi), label = label )
#####
matlines( x, cbind(y1, y2, y3), col = c("red", "green", "blue"), lty = 1:3, lwd = 1:3 )
legend( "topleft", legend = c("y1", "y2", "y3"), col = c("red", "green", "blue"), lty = 1:3, lwd = 1:3 )
#################################### # 顏色
# palette( )
par( mex = 0.8, mar = c(4, 2, 2, 2) + 0.1 )
barplot( 1:8, col = palette(), names.arg = 1:8, yaxt = "n" )
n <- 10
par( mfrow = c(2, 3), mex = 0.6, mar = c(5, 4, 4, 2) + 0.1 )
barplot( 1:n, col = colors()[1:n], names.arg = 1:n, yaxt = "n", main = "colors" )
barplot( 1:n, col = rainbow(n), names.arg = 1:n, yaxt = "n", main = "rainbow" )
barplot( 1:n, col = heat.colors(n), names.arg = 1:n, yaxt = "n", main = "heat.colors" )
barplot( 1:n, col = terrain.colors(n), names.arg = 1:n, yaxt = "n", main = "terrain.colors" )
barplot( 1:n, col = topo.colors(n), names.arg = 1:n, yaxt = "n", main = "topo.colors" )
barplot( 1:n, col = cm.colors(n), names.arg = 1:n, yaxt = "n", main = "cm.colors" )
# cm: cyan-magenta
layout(1)
gray.scale <- seq( from = 0, to = 1, length = 64 )
par( mex = 0.8, mar = c(4, 2, 2, 2) + 0.1 )
barplot( 1:64, col = gray(gray.scale), yaxt = "n", main = "gray scale" )
# From 0 (black) -> 1 (white)
layout(1)
par( mex = 0.8, mar = c(4, 2, 2, 2) + 0.1 )
palette( terrain.colors(30) )
barplot( 1:100, col = 20, yaxt = "n" )
palette( "default" )
barplot( 1:20, col = 1:20, names.arg = 1:20, yaxt = "n" )
par( bg = "green", col.main = "navy", col.lab = "magenta", mex = 0.8, mar = c(5, 5, 4, 3) + 0.1 )
plot( 0:10, 0:10, pch = 16, col = rainbow(10), main = "Main title", xlab = "X axis", ylab = "Y axis", axes = FALSE )
par( bg = "lightyellow", col.main = "navy", col.lab = "magenta", mex = 0.8, mar = c(5, 5, 4, 3) + 0.1 )
plot( 0:10, 0:10, pch = 16, col = rainbow(10), main = "Main title", xlab = "X axis", ylab = "Y axis", axes = FALSE )
axis( side = 1, col = "black", col.axis = "red", at = 0:10, label = LETTERS[1:11] )
axis( side = 2, col = "green", col.axis = "blue", at = seq(from = 0, to = 10, by = 1) )
axis( side = 3, col = "cyan", col.axis = "magenta", at = seq(from = 0, to = 8, by = 1) )
axis( side = 4, col = "yellow", col.axis = "gray", at = seq(from = 2, to = 10, by = 2), label = c(20, 40, 60, 80, 100) )
mtext( text = c( "Bottom", "Left", "Top", "Right" ), side = 1:4, col = 1:4, line = -2 )