17.1 The basics

  • Understanding the basic workings of graphs is essential for creating more complex visualizations
  • Most simply: plot()
    • A generic function (Q: What does that mean again?)
    • Opens a window, produces some plot, draws axes and a box around it
  • Steps
    • Open window: windows(8,8) and quartz(8,8)
    • Create graph: e.g. plot(x)
    • Save the plot
      • savePlot(filename="./figures/test.pdf", type="pdf")
        • Choose format with type = c("wmf", "emf", "png", "jpg", "jpeg", "bmp", "tif", "tiff", "ps", "eps", "pdf"
    • Close window: dev.off()
  • Or directly pdf() (and dev.off() after)


17.1.1 Example: Basic steps

getwd()

# Open window
windows(8,8) # DINA4 page has a width of 8,27 inches
# MAC?

# Create histogram
plot(rnorm(n=101,sd=.8))
hist(rnorm(n=101,sd=.8))

# Save
savePlot(filename="test.jpg", type="jpg")

# Close the graphics window
dev.off()

# If you work on a server where it's not possible to open windows

# open device
pdf("test2.pdf")

# create a histogram
hist(rnorm(n=101,sd=.8))

# close device
dev.off()