Plotting with ggplot2

Wilkinson (2005) developed The Grammar of Graphics as a way of approaching data visualization by describing them as individual components working together. Wickham (2010) used this grammar to develop the ggplot2 package. In ggplot2, you can create plots by adding each component of the visualization as a layer. In this section, you will recreate a scatterplot from Chapter 4 , Linear Regression for Business that you built using base R graphics. Convert emp_size to a factor to see its effect in visualizing information:

plot_dat <- read.csv("./data/Ch7_marketing.csv") plot_dat$emp_size <- cut(plot_dat$employees, breaks = 3, labels = c("Employees: 3 - 6", "7 - 9", "10+")) library(ggplot2); library(scales) plot <- ggplot(data ...

Get Introduction to R for Business Intelligence now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.