Figure 14-3: Windows Fonts

Portfolio Categories: All Graphics and SGR Book Graphics.

Demonstration of Windows Fonts in R Graphics

Using Windows Fonts with R Graphics



# Check windows font mappings
windowsFonts()                         # Show windows font mappings

# 14.2b Remapping windows fonts ========================================== 14.2b

png(filename = "illustrations/fig-14-3-windowsFonts.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(mfcol = c(2, 1))                   # Set up 2 plots vertically
par(mai = c(.85, .85, .5, .25))        # Set margins
windowsFonts(                          # Reassign the sans font 
  sans = "TT Comic Sans MS")           #   to Comic Sans
plot(myV1, myV2, type = "b",           # A simple plot 
  main = "Some Comic Sans Action!",    # A Title
  family = "sans")                     # Font family for plot

windowsFonts(                          # Reassign serif font
  serif = "TT Blackadder ITC")         #   to Blackadder ITC
plot(myV1, myV2, type = "b",           # A simple plot 
  main = 
    "Please don't use this font!",     # A title for the plot
  family = "serif")                    # Font family for plot

dev.off()                              # Output png file

# Reset fonts to defaults (Please!)
windowsFonts(sans = "TT Arial")        # Reset fonts back to defaults
windowsFonts(serif = "TT Times New Roman")