Skip to content

Instantly share code, notes, and snippets.

@hadley
Created August 5, 2015 14:36
Show Gist options
  • Select an option

  • Save hadley/ba3962c7a18ec5ed0b77 to your computer and use it in GitHub Desktop.

Select an option

Save hadley/ba3962c7a18ec5ed0b77 to your computer and use it in GitHub Desktop.
df <- data.frame(
x = 1:5,
y = 1:5,
z = factor(c(1, 2, 3, 3, 3))
)
ggplot(df, aes(x, y)) +
geom_rect(aes(ymin = -Inf, ymax = Inf, xmin = x - 0.5, xmax = x + 0.5, fill = z)) +
geom_point() +
scale_fill_grey()
@jimhester
Copy link
Copy Markdown

This seems to work fine for geom_bar()

ggplot(df, aes(x, y)) +
  geom_rect(aes(ymin = -Inf, ymax = Inf, xmin = x - 0.5, xmax = x + 0.5, fill = z)) +
  geom_bar(stat = "identity") + 
  scale_fill_grey(start = .9, end = .6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment