# Figure 3.1: A graphic representation of my R objects approach ----------------
# This is just an exercise in drawing with R. The code doesn't really serve
# much purpose beyond that. But, if you are needing to do work with shapes
# following the lead from Chapter 14, you might find some bits of use.
# 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-1-R objects schema.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
oval(xcen = .55, ycen = .5, # Top oval for obj type container
xlen = .175, ylen = .025, # Length of radii
ewidth = 2, # Line width
ecolor = "gray") # Line color
myArrow(x0 = .26, x1 = .445, # Arrow from storage mode to object
y0 = .75, y1 = .75,
angle = 45, # Set arrowhead angle
ljoin = 1, # Set line join type
lwd = 25, # Set line join type
col = "light gray") # Set color
polygon( # Arrow body
x = c(.5, .5, .6, .6),
y = c(.55, .7, .7, .55),
col = "light gray",
border = "light gray")
polygon( # Arrow head
x = c(.55, .475, .625),
y = c(.49, .55, .55),
col = "light gray",
border = "light gray")
myArrow(x0 = .8, x1 = .655, # Arrow from class to object
y0 = .85, y1 = .75,
L = .25, # Set length of arrowhead
angle = 30, # Set arrowhead angle
ljoin = 2, # Set line join type
lwd = 10, # Set line join type
col = "light gray") # Set color
polygon( # Rectangle around Storage Mode
x = c(.001, .001, .249, .249),
y = c(.45, .99, .99, .45),
col = "white",
lwd = 2,
border = "gray")
polygon( # Rectangle around pseudo-Storage Mode
x = c(.001, .001, .249, .249),
y = c(.45, .625, .625, .45),
col = gray(.8),
lwd = 2,
border = "gray")
polygon( # Rectangle around Class
x = c(.8, .8, .95, .95),
y = c(.8, .9, .9, .8),
col = "white",
lwd = 2,
border = "gray")
symbols(x = .55, y = .75, # Filled circle behind R Data Object
circles = .1, # Set circle size
inches = FALSE, # Don't constrain to inch size
add = TRUE, # Add to current plot
bg = "white") # Set background color
oval(xcen = .55, ycen = .75, # Circle around R Data Object in center
xlen = .1, ylen = .1*(3/2), # Y radius adjusted for aspect ratio
ewidth = 6, # Set line size
ecolor = "gray") # Set color
text(x = .55, y = .75, # R Data Object Text
labels = "R Data\nObject",
cex = 1.5, # Set font size
font = 2, # Bold
family = "serif") # Serif Font
text(x = .55, y = .375, # Data Object Type Text
labels = "Data Object Type",
pos = 3, # Above and centered
cex = 1.25, # Set font size
font = 2, # Bold
family = "serif") # Serif Font
text(x = .55, y = .325, # List of Data Object Types
labels = "Vector\nMatrix\nData Frame\nList",
pos = 1, # Below and centered
cex = 1, # Set font size
family = "sans") # Sans serif font
text(x = .125, y = .9, # Data Object Storage Mode Text
labels = "Storage Mode",
pos = 3, # Above and centered
cex = 1.25, # Set font size
font = 2, # Bold
family = "serif") # Serif Font
text(x = .125, y = .85, # Storage Modes List
labels = "Logical\nNumeric\nCharacter\n\n\nDate/Time\nFactor",
pos = 1, # Below and centered
cex = 1, # Set font size
family = "sans") # Sans serif font
text(x = .875, y = .85, # Data Object Class Text
labels = "Class",
cex = 1.25, # Set font size
font = 2, # Bold
family = "serif") # Serif Font
oval(xcen = .55, ycen = .05, # Bottom oval for obj type container
xlen = .175, ylen = .025,
ewidth = 2,
ecolor = "gray")
segments(x0 = .375, x1 = .375, # Left line for object type container
y0 = .05, y1 = .5,
lwd = 2,
col = "gray")
segments(x0 = .725, x1 = .725, # Right line for object type container
y0 = .05, y1 = .5,
lwd = 2,
col = "gray")
dev.off() # Output png file
Figure 3-1: R Objects
Portfolio Categories: All Graphics and SGR Book Graphics.