knitr::opts_chunk$set(echo = TRUE, fig.height = 4, fig.width = 6)
This file documents functions used for drawing histograms in the Price-Promotion-Analysis papers.
if(!require(CommonFunctions)){ devtools::install_github('georgegui/CommonFunctions') library(CommonFunctions) } library(data.table) library(gridExtra)
The function will plot the median of the distribution as a vertical red line. It will also automatically asign meaningful ticks on the x-axis. The default will include 0 into the axis and will truncate the outliers.
iris <- data.table(iris) ggplot_list <- list()
ggplot_list[[1]] <- PrettyPlot(iris, 'Sepal.Length', include_0 = F) ggplot_list[[1]]
ggplot_list[[2]] <- PrettyPlot(iris, 'Sepal.Length', include_0 = F, weight = 'Sepal.Width') ggplot_list[[2]]
We can also first specifiy X-axis and pass it to the plot function.
my_axis <- GenerateAxisX(iris$Sepal.Length, min_x = 4, max_x = 8, xtitle = 'Sepal Length') ggplot_list[[3]] <- PrettyPlot(iris, 'Sepal.Length', scalex = my_axis) ggplot_list[[3]]
iris[, is_setosa := Species == 'setosa'] ggplot_list[[4]] <- PrettyPlot( iris, 'Sepal.Length', include_0 = F, x_full_range = T, color_legend = 'is_setosa') ggplot_list[[4]]
grid.arrange(grobs = ggplot_list)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.