library(tidyverse)
library(scales)
#>
#> Attaching package: 'scales'
#> The following object is masked from 'package:purrr':
#>
#> discard
#> The following object is masked from 'package:readr':
#>
#> col_factor
library(cowplot)
#>
#> Attaching package: 'cowplot'
#> The following object is masked from 'package:ggplot2':
#>
#> ggsave
library(dplyr)
library(ggplot2)
library(reprex)
library("datapasta")
df3a = structure(list(category = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), .Label = c("0%",
"1%-10%", "11%-20%", "21%-30%", "31%-40%", "41%-50%", "51%-60%",
"61%-70%", ">= 71%"), class = "factor"), PROGRAM_LEVEL_DESCR = structure(c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L,
2L, 4L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L, 1L, 2L, 3L, 4L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 6L, 7L,
9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 2L, 3L, 4L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 14L, 1L, 2L, 3L, 4L, 6L, 7L, 9L, 10L, 11L, 12L, 13L,
14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L,
1L, 2L, 3L, 4L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L), .Label = c("Branch Refusal",
"Club", "Corporate Refusal", "Credit Hold", "Customer Refusal",
"Diamond", "Enrollment", "Failed 2X in Calendar Year", "Gold",
"Institutional", "No Program", "Platinum", "RSVP", "Silver"), class = "factor"),
count = c(133L, 172L, 5L, 215L, 1L, 104L, 389L, 13L, 843L,
193L, 10743L, 482L, 10L, 1695L, 3L, 383L, 59L, 471L, 98L,
2L, 1675L, 87L, 1284L, 1719L, 1351L, 6L, 290L, 3L, 39L, 262L,
85L, 3L, 1123L, 76L, 1255L, 1003L, 1L, 1000L, 3L, 208L, 5L,
31L, 189L, 69L, 731L, 79L, 979L, 670L, 1L, 732L, 1L, 156L,
8L, 33L, 1L, 127L, 70L, 1L, 547L, 55L, 967L, 480L, 1L, 568L,
150L, 5L, 31L, 85L, 65L, 2L, 416L, 38L, 907L, 319L, 531L,
1L, 102L, 14L, 18L, 63L, 35L, 307L, 25L, 533L, 236L, 2L,
317L, 3L, 90L, 18L, 22L, 1L, 33L, 38L, 1L, 254L, 25L, 640L,
180L, 275L, 8L, 179L, 48L, 76L, 100L, 150L, 5L, 503L, 95L,
4032L, 339L, 2L, 812L)), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -113L), vars = "category", drop = TRUE)
df3a %>%
ggplot(aes(x=category, y=count)) +
geom_bar(aes(fill = PROGRAM_LEVEL_DESCR),stat='identity') +
labs(y='Number of Distinct Customers', x=' # of PL Orders in the PL Cart') +
geom_text(aes(label=sprintf("%1.1f%%", percent)),
position=position_stack(vjust=0.5), size=3, colour="white")
#> Error in as.double(function (x) : cannot coerce type 'closure' to vector of type 'double'
Created on 2018-06-29 by the reprex
package (v0.2.0).