If we endeavor to develop a charting instead of a graphing program, we will accomplish two things. First, we inevitably will offer fewer charts than people want. Second, our package will have no deep structure. Our computer program will be unnecessarily complex, because we will fail to reuse objects or routines that function similarly in different charts. And we will have no way to add new charts to our system without generating complex new code. Elegant design requires us to think about a theory of graphics, not charts.
ggplot(
data = mpg,
mapping = aes(x = cty, y = hwy, color = factor(cyl))
) +
geom_point()
These elements form a layer:
ggplot(data = mpg, mapping = aes(x = cty, y = hwy, col = factor(cyl))) +
geom_point() +
geom_abline(slope = 1, intercept = 0, color = 'black', linetype = 'dotted')
ggplot(data = mpg, mapping = aes(x = cty, y = hwy, col = factor(cyl))) +
geom_point() +
geom_abline(slope = 1, intercept = 0, color = 'black', linetype = 'dotted') +
scale_color_manual(name = '# of Cyl', values = c('skyblue','royalblue', 'blue', 'navy')) +
coord_fixed(ratio = 1) +
facet_grid(.~class)