# Figure 3.2 - A graphic showing factor vectors --------------------------------
# This is another exercise in drawing with R.
# This starts with the custom ovals function from chapter 10 and the
# custom arrows function from chapter 14 already loaded.
png(filename = "illustrations/fig-3-2-R factors.png",
units = "in", # Set measurements in inches
res = 1200, # Set resolution at 1200dpi
width = 6, # Width at 6 inches
height = 4) # Height at 4 inches
par(mai = c(0, 0, 0, 0)) # Set margins - no Title
par(usr = c(0, 1, 0, 1)) # Set coordinates to 0,1 space
plot.new() # Start a new plot
text(x = .15, y = .97, # The vector you see text
labels = "The vector\nyou see:",
pos = 1, # Place text below and centered
cex = 1.5, # Set font size
font = 2, # Bold
family = "serif")
text(x = .15, y = .65, # What you see vector
labels='
"Small"\n"Small"\n"Large"\n"Large"\n"Large"\n"Small"\n"Small"',
pos = 1, # Place text below and centered
cex = 1, # Font size
family = "sans")
lines(
x = c(.09, .075, .075, .09), # Add brackets for what you see vector
y = c(.65, .65, .2, .2),
col = "black",
lwd = 2)
lines(
x = c(.21, .225, .225, .21),
y = c(.65, .65, .2, .2),
col = "black",
lwd = 2)
segments(x0 = .3, x1 = .3, # Dividing Line
y0 = .05, y1 = .95,
lwd = 4,
col = "gray")
text(x = .6, y = .97, # Vectors R Sees text
labels = "The vectors R sees:",
pos = 1, # Place text below and centered
cex = 1.5, # Font size
font = 2,
family = "serif")
text(x = .45, y = .89, # Levels Vector text
labels = "The\nLevels\nVector",
pos = 1, # Place text below and centered
cex = 1, # Font size
font = 2, # Bold
family = "serif")
text(x = .45, y = .625, # Levels Vector
labels = 'L1: "L"\nL2: "S"',
pos = 1, # Place text below and centered
cex = 1, # Font size
family = "sans")
lines( # Add brackets for levels vector
x = c(.39, .375, .375, .39),
y = c(.65, .65, .475, .475),
col = "black",
lwd = 2)
lines(
x = c(.51, .525, .525, .51),
y = c(.65, .65, .475, .475),
col = "black",
lwd = 2)
# Pointers vector text
text(x = .6, y = .89,
labels = "The\nPointers\nVector",
pos = 1, # Place text below and centered
cex = 1, # Font size
font = 2, # Bold
family = "serif")
text(x = .6, y = .62, # Pointers vector
labels = "2\n2\n1\n1\n1\n2\n2",
pos = 1, # Place text below and centered
cex = 1.05, # Font size
family = "sans")
lines( # Add brackets for pointers vector
x = c(.565, .55, .55, .565),
y = c(.65, .65, .2, .2),
col = "black",
lwd = 2)
lines(
x = c(.635, .65, .65, .635),
y = c(.65, .65, .2, .2),
col = "black",
lwd = 2)
text(x = .75, y = .89, # Labels vector text
labels = "The\nLabels\nVector\n(optional)",
pos = 1, # Place text below and centered
cex = 1, # Font size
font=2, # Bold
family = "serif")
text(x = .75, y = .625, # Labels vector
labels = '"Large"\n"Small"',
pos = 1, # Place text below and centered
cex = 1, # Font size
family = "sans")
lines( # Add brackets for labels vector
x = c(.69, .675, .675, .69),
y = c(.65, .65, .475, .475),
col = "black",
lwd = 2)
lines(
x = c(.81, .825, .825, .81),
y = c(.65, .65, .475, .475),
col = "black",
lwd = 2)
dev.off() # Output png file
Figure 3-2: R Factor Objects
Portfolio Categories: All Graphics and SGR Book Graphics.