Skip to content

Instantly share code, notes, and snippets.

@aravindhebbali
Last active September 25, 2017 09:47
Show Gist options
  • Save aravindhebbali/096329693fa1f9313771d4e259cce1ec to your computer and use it in GitHub Desktop.
Save aravindhebbali/096329693fa1f9313771d4e259cce1ec to your computer and use it in GitHub Desktop.
ggplot2: Bar Plot
# install
install.packages('ggplot2')
install.packages('readr')
# library
library(ggplot2)
library(readr)
# Simple Bar Plot
ggplot(ecom) +
geom_bar(aes(factor(device)))
# Bar Color
ggplot(ecom) +
geom_bar(aes(factor(device)),
fill = c('red', 'blue', 'green'))
# Stacked Bar Plot
ggplot(ecom) +
geom_bar(aes(device, fill = factor(referrer)))
# Grouped Bar Plot
ggplot(ecom) +
geom_bar(aes(device, fill = factor(referrer)), position = 'dodge')
# Proportional Bar Plot
ggplot(ecom) +
geom_bar(aes(device, fill = factor(referrer)), position = 'fill')
# Horizontal Bar Plot
ggplot(ecom) +
geom_bar(aes(factor(device), fill = factor(referrer))) +
coord_flip()
# Bar Line Color
ggplot(ecom) +
geom_bar(aes(factor(device)), fill = 'white',
color = c('red', 'blue', 'green'))
# Bar Line Type
ggplot(ecom) +
geom_bar(aes(factor(device)), fill = 'white',
color = 'black', linetype = 2)
# Bar Line Size
ggplot(ecom) +
geom_bar(aes(factor(device)), fill = 'white',
color = 'black', size = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment