Last active
September 25, 2017 10:09
-
-
Save aravindhebbali/674bc30cc1539d735bdc4e6210982d1d to your computer and use it in GitHub Desktop.
ggplot2: Histogram
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) | |
# import data | |
ecom <- readr::read_csv('https://raw.githubusercontent.com/rsquaredacademy/datasets/master/web.csv') | |
ecom | |
# Histogram | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit)) | |
# Specify Bins | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit), bins = 7) | |
# Fill | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit), bins = 7, fill = 'blue') | |
# Alpha | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit), bins = 7, fill = 'blue', alpha = 0.3) | |
# Color | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit), bins = 7, fill = 'white', color = 'blue') | |
# Bins, Color & Fill | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit), bins = 7, fill = 'blue', color = 'white') | |
# Bin Width | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit), binwidth = 2, fill = 'blue', color = 'black') | |
# Line Type | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit), bins = 5, fill = 'white', | |
color = 'blue', linetype = 3) | |
# Line Size | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit), bins = 5, fill = 'white', | |
color = 'blue', size = 1.25) | |
# Map Fill to Variable | |
ggplot(ecom) + | |
geom_histogram(aes(n_visit, fill = device), bins = 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment