Skip to content

Instantly share code, notes, and snippets.

@jsonbecker
Created December 1, 2016 04:01
Show Gist options
  • Save jsonbecker/0cc702804512fdf29c7f9067adfc17d0 to your computer and use it in GitHub Desktop.
Save jsonbecker/0cc702804512fdf29c7f9067adfc17d0 to your computer and use it in GitHub Desktop.
How do I get labels on this plot?
library(ggplot2)
df <- data.frame(type = c(rep('Elementary', 2), rep('Middle', 2), rep('High', 2)),
included = rep(c('included','excluded'),3),
dollars = c(1000, 2500, 4000, 1000, 3000, 2800))
ggplot(data = df, aes(type, dollars, fill = included)) +
geom_bar(position = 'fill', stat = 'identity') +
geom_text()
@cpsievert
Copy link

Another option is to leverage ggplotly()'s ability to return data after statistics have been applied:

https://cpsievert.github.io/plotly_book/extending-ggplotly.html#leveraging-statistical-output

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