Set up

library("ggplot2")
data(bond, package = "jrGgplot2")
(g = ggplot(data = bond, aes(x = Alcohol_Units, y = Kills)) + 
  geom_point(aes(colour = Actor)))

(g1 = g + scale_colour_hue(l = 70, c = 60))

(g2 = g + scale_colour_brewer(palette = "PuOr", type = "div"))

# Colours for amusement rather than clarity
(g3 = g + scale_colour_manual(values = c(
    "Brosnan" = rgb(192, 192, 192, maxColorValue = 255), #silver
    "Connery" = "Gold",
    "Craig" = rgb(205, 127, 50, maxColorValue = 255), #Bronze 
    "Dalton" = "tomato1",
    "Lazenby" = "tomato2",
    "Moore" = "tomato3")))

(g4 = g + scale_colour_grey())

More advanced layouts

We have to create our own function. Well, we don't "have" to but it makes life easier further down the line.

library("grid")
vplayout = function(x, y) 
  viewport(layout.pos.row = x, layout.pos.col = y)

Now we can use our vplayout() function to create custom layouts.

grid.newpage()
pushViewport(viewport(layout = grid.layout(2, 2)))

print(g1, vp = vplayout(1, 1:2))
print(g2, vp = vplayout(2, 1))
print(g3, vp = vplayout(2, 2))


jr-packages/jrGgplot2 documentation built on Sept. 20, 2020, 2:59 a.m.