Last active
September 25, 2017 09:47
-
-
Save aravindhebbali/096329693fa1f9313771d4e259cce1ec to your computer and use it in GitHub Desktop.
ggplot2: Bar Plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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