#install.packages("tidyverse")
#install.packages("ggplot2")
#install.packages("packcircles")
#install.packages("readxl")
#install.packages("data.table")
#install.packages("dplyr")
library(data.table)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:data.table':
##
## between, first, last
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readxl)
library(ggplot2)
library(packcircles)
library(ggrepel)
Craigs_GL2 <- read_excel("~/Vinifer Accounting/Examples/Craigs GL2.xlsx")
data <- Craigs_GL2
remove(Craigs_GL2)
data1 <- rename(data, "Acct" = "Account Type", "Detail" = "Account Detail", "Type" = "Transaction Type", "Memo" = "Memo/Description")
DT <- data.table(filter(data1, Acct == "Income"))
summary <- DT[, sum(Amount), by=Name]
ggplot(summary, aes(x = Name, y = V1, size = V1)) + geom_point(shape = 21, colour = "black", fill = "cornsilk")
g <- ggplot(summary, aes(x = Name, y = V1, size = V1)) + geom_point(shape = 21, colour = "black", fill = "cornsilk")
g + scale_size_area(max_size = 20)
## add labels to circles
g + scale_size_area(max_size = 20) + geom_text_repel(aes(label = Name), size = 3)
## Create a dataframe with one line representing one of the bubbles. It
has x & y coordinates which are the center of the bubble and a
radius. It names this dataframe packing.
packing <- circleProgressiveLayout(summary$V1, sizetype = "area")
## Warning in circleProgressiveLayout(summary$V1, sizetype = "area"): missing and/
## or non-positive sizes will be ignored
summary <- cbind(summary, packing)
dat.gg <- circleLayoutVertices(packing, npoints = 50)
ggplot() +geom_polygon(data = dat.gg, aes(x, y, group = id, fill=as.factor(id)), colour = "black", alpha = 0.6)
i <- ggplot() +geom_polygon(data = dat.gg, aes(x, y, group = id, fill=as.factor(id)), colour = "black", alpha = 0.6)
i + geom_text(data = summary, aes(x, y, size = V1, label = Name))
## Warning: Removed 3 rows containing missing values (geom_text).
j <- i + geom_text(data = summary, aes(x, y, size = V1, label = Name))
j + scale_size_continuous(range = c(1,5))
## Warning: Removed 3 rows containing missing values (geom_text).
k <- j + scale_size_continuous(range = c(1,5))
k + theme_void() + theme(legend.position = "none")
## Warning: Removed 3 rows containing missing values (geom_text).
l <- k + theme_void() + theme(legend.position = "none")
l + coord_equal()
## Warning: Removed 3 rows containing missing values (geom_text).
m <- l + coord_equal()
install.packages(“viridis”)
dat.gg$value <- rep(summary$V1, each=51)
ggplot() + geom_polygon(data = dat.gg, aes(x, y, group = id, fill = value), colour = "black", alpha = 0.6) + scale_fill_distiller(palette = "Greens", direction = 1)
n <- ggplot() + geom_polygon(data = dat.gg, aes(x, y, group = id, fill = value), colour = "black", alpha = 0.6) + scale_fill_distiller(palette = "Greens", direction = 1)
n + geom_text(data = summary, aes(x, y, size = V1, label = Name)) + scale_size_continuous(range = c(1,5)) + theme_void() + theme(legend.position = "none") + coord_equal()
## Warning: Removed 3 rows containing missing values (geom_text).
## Change the background(s) to black in the “plot.background” section of
theme() ## Change geom_text to geom_label to change black text to
visible
n + geom_label(data = summary, aes(x, y, size = V1, label = Name)) + scale_size_continuous(range = c(1,5)) + theme_void() + theme(legend.position = "none", plot.background = element_rect(fill = "black")) + coord_equal()
## Warning: Removed 3 rows containing missing values (geom_label).
## Add a title at the end using ggtitle()
n + geom_label(data = summary, aes(x, y, size = V1, label = Name)) + scale_size_continuous(range = c(1,5)) + theme_void() + theme(legend.position = "none", plot.background = element_rect(fill = "black"), plot.title = element_text(color = "white")) + coord_equal() + ggtitle("Craigs Landscaping Customers")
## Warning: Removed 3 rows containing missing values (geom_label).
## space the circles out to easier see the labels ## 1. reduce the
radius
packing$radius <- 0.75*packing$radius
summary.9 <- cbind(summary, packing)
summary.9 <- subset(summary.9, select = -x)
summary.9 <- subset(summary.9, select = -y)
summary.9 <- subset(summary.9, select = -radius)
n + geom_label(data = summary.9, aes(x, y, size = V1, label = Name)) + scale_size_continuous(range = c(1,5)) + theme_void() + theme(legend.position = "none", plot.background = element_rect(fill = "black"), plot.title = element_text(color = "white")) + coord_equal() + ggtitle("Craigs Landscaping Customers")
## Warning: Removed 3 rows containing missing values (geom_label).
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.