#################################################
# A05: 基礎統計圖形                             #
# 吳漢銘 國立政治大學統計學系                   #
# https://hmwu.idv.tw                           #
#################################################


# 2/86
browseURL("https://r-graph-gallery.com/")



# 6/86
head(anscombe, 3)
apply(anscombe, 2, mean)
apply(anscombe, 2, sd)
mapply(cor, anscombe[, 1:4], anscombe[, 5:8])
mapply(function(x, y)
  lm(y ~ x)$coefficients, anscombe[, 1:4], anscombe[, 5:8])

par(mfrow = c(2, 2))
regplot <- function(x, y) {
  plot(y ~ x)
  abline(lm(y ~ x), col = "red")
}
mapply(regplot, anscombe[, 1:4], anscombe[, 5:8])



# 7/86
plot(iris[, 1])

postscript(file = "iris2.ps")
plot(iris[, 2])
dev.off()

jpeg(file = "iris3.jpg")
plot(iris[, 3])
dev.off()



# 10/86
pdf("iris.pdf") # jpeg, bmp OK
plot(iris[, 1:2], xlab = "花萼長", ylab = "花萼寬", main = "鳶尾花 散佈圖",
  col = iris[, 5]
)
text(6.7, 4, "這是中文")
dev.off()

library(showtext) #showtext: Using Fonts More Easily in R Graphs
font.add("msjh", "msjh.ttc") ## 微軟正黑體
showtext.auto(enable = TRUE)



# 11/86
pdf("test.pdf", width = 6, height = 4)
# ?bmp (jpeg, png, tiff)
par(family = "msjh") ## 微軟正黑體

par(mfrow = c(1, 2), oma = c(2, 1, 2, 1))
hist(iris[, 1])
text(6, 20, "這裡有中文字", col = "green", cex = 2)
plot(iris[, 1], iris[, 2], xaxt = "n", bty = "n", xlab = "",
  xlim = c(0, 8), ylim = c(0, 5)
)
axis(1, at = 0:8 , labels = letters[1:9], tick = FALSE)
text(2, 3, "我是中文", col = "red", cex = 2)
title('主標題(family="fang")', family = "fang", outer = TRUE,
  line = -1, cex.main = 2)
mtext("這裡也有文字喲!", side = 1, line = 6, at = 6, col = "blue"
)
mycolor <- rainbow(100, alpha = 0.6)[1:80]
rasterImage(t(mycolor), 0, 0, 8, 1, interpolate = FALSE)
dev.off()



# 14/86
x <- iris[, 1]
plot(x)
hist(x)
boxplot(x)



# 15/86
library(MASS)
data(gehan)
time <- gehan$time

par(mfrow = c(2, 1))
plot(time, ylim = c(-5, 50), main = "Scatterplot of time")
boxplot(time, ylim = c(-5, 50), main = "Boxplot of time")

par(mfrow = c(2, 1))
s.title <- "Scatterplot of time"
plot(time, ylim = c(-5, 50), main = s.title)
b.title <- "Boxplot of time"
boxplot(time, ylim = c(-5, 50), main = b.title)



# 16/86
y <- iris[, 1]
plot(y, type = "l", lwd = 3)
plot(y, type = "l", col = "red")
plot(y, type = "l", lty = "dashed")



# 17/86
y <- iris[, 1]
plot(y, type = "p") # points
plot(y, type = "l") # lines
plot(y, type = "b") # both
plot(y, type = "h") #histogram-like
plot(y, type = "n") # none



# 18/86
attach(iris)
plot(Sepal.Length, Petal.Length,
     xlim = c(-1, max(Sepal.Length)), ylim = c(-1, max(Petal.Length)))
abline(lm(Petal.Length ~ Sepal.Length), col = "black")
abline(h = 0, col = "grey")
abline(v = 0, col = "grey")
abline(h = 2, col = "red", lty = 2)
abline(v = 5.5, col = "blue", lty = 3)
abline(a = 1, b = 0.7, col = "green", lty = 4, lwd = 2
)
detach(iris)



# 19/86
x <- iris[, 1]
y <- iris[, 3]
plot(x, y, pch = 16, col = "red")
lines(x, y)

sequence <- order(x)
plot(x, y, pch = 16, col = "red")
lines(x[sequence], y[sequence])



# 20/86
x <- runif(12)
y <- rnorm(12)
plot(x, y, main = "arrows and segments")
arrows(x[1], y[1], x[2], y[2], col = "black", length = 0.2)
segments(x[3], y[3], x[4], y[4], col = "red")
segments(x[3:4], y[3:4], x[5:6], y[5:6], col = c("blue", "green"))



# 23/86
op <- par()
par(col = "red")
plot(1, 2)
par(op)

par(c("col", "lty"))
par(col = "red", lty = "dashed")
y <- rnorm(20)
plot(y, type = "l") # dashed line
plot(y, type = "l", lty = "solid") # solid line
plot(y, type = "l") # dashed line



# 25/86
myplot <- function(n) {
  for (i in 1:n) {
    plot(1, type = "n", xaxt = "n", yaxt = "n", xlab = "", ylab = "")
    text(1, 1, labels = paste(i), cex = 3)
  }
}

orig.par <- par(mai = c(0.1, 0.1, 0.1, 0.1), mfrow = c(3, 2))
myplot(6)
par(orig.par)
par(mai = c(0.1, 0.1, 0.1, 0.1), mfcol = c(2, 3))



# 26/86
plot(1:10, rep(1, 10), pch = 20, col = 1:10, cex = 5, xlab = "", ylab = "")
text(1:10, rep(1.2, 10), labels = 1:10)



# 27/86
par(mfrow = c(2, 3))
n <- 24
pie(rep(1, n), col = rainbow(n))
pie(rep(1, n), col = heat.colors(n))
pie(rep(1, n), col = terrain.colors(n))
pie(rep(1, n), col = topo.colors(n))
pie(rep(1, n), col = cm.colors(n))
pie(rep(1, n), col = grey(1:n / n))



# 28/86
library(RColorBrewer)
brewer.pal.info
display.brewer.all()



# 29/86
display.brewer.pal(5, "BrBG")
display.brewer.pal(7, "BrBG")
display.brewer.pal(9, "BrBG")

attach(iris)
par(mfrow = c(1, 6))
hist(Sepal.Length, breaks = 10, col = brewer.pal(3, "Set3"), 
     main = "Set3 3 colors")
hist(Sepal.Length, breaks = 3 , col = brewer.pal(3, "Set2"),
     main = "Set2 3 colors")
hist(Sepal.Length, breaks = 7, col = brewer.pal(3, "Set1"),
     main = "Set1 3 colors")
hist(Sepal.Length, breaks = 2, col = brewer.pal(8, "Set3"),
  main = "Set3 8 colors")
hist(Sepal.Length, col = brewer.pal(8, "Greys"), main = "Greys 8 colors")
hist(Sepal.Length, col = brewer.pal(8, "Greens"), main = "Greens 8 colors")



# 29/86
library(fields)
par(mfcol = c(3, 2))
x <- 1:20
y <- 1:20
z <- outer(x, rep(1, 20), "+")
obj <- list(x = x, y = y, z = z)
image(obj, col = tim.colors(200), main = "tim.colors(200)")
image(obj, col = two.colors(), main = "two.colors()")
image(obj, col = two.colors(start = "darkgreen", 
                            end = "darkred", 
                            middle = "black"),
      main = "two.colors()"
)
plot(x, y,  main = "two.colors(alpha=.5)")
image(obj, col = two.colors(alpha = .5), add = TRUE)
image(obj, col = designer.colors(), main = "designer.colors()")
coltab <- designer.colors(col = c("blue", "grey", "green", "red"))
image(obj, col = coltab, main = "designer.colors()")



# 31/86
plot(iris[, 3], iris[, 4], type = "n")
my.label <- c(rep("a", 50), rep("b", 50), rep("c", 50))
text(iris[, 3], iris[, 4], labels = my.label, cex = 0.7)



# 32/86
plot(iris[, 3], iris[, 4], type = "n")
my.label <- c(rep("a", 50), rep("b", 50), rep("c", 50))
text(iris[, 3], iris[, 4], my.label, cex = 0.7, 
     col = ifelse(iris[, 1] > median(iris[, 1]), "red", "blue"))



# 33/86
plot(iris[, 1], iris[, 2], xlim = c(0, 10), ylim = c(0, 10))
text(2, 8, "This is a test")
arrows(x0 = 3, y0 = 7, x1 = 5, y1 = 5, length = 0.15, col = "red")
text(4, 9, expression(hat(beta) == (X ^ t * X) ^ {-1} * X ^ t * y))



# 34/86
plot(rep(1:5, 5), rep(1:5, each = 5), pch = 1:25, cex = 2,
     xaxt = "n", xlab = "", yaxt = "n", ylab = "", 
     xlim = c(0, 6), ylim = c(0, 6))
text(rep(1:5, 5) - 0.2, rep(1:5, each = 5), 1:25, cex = 1)



# 35/86
plot(iris[, 3], iris[, 4], type = "n")
my.label <- c(rep("a", 50), rep("b", 50), rep("c", 50))
my.color <- c(rep("red", 50), rep("blue", 50), rep("green", 50))
text(iris[, 3], iris[, 4], my.label, cex = 0.7, col = my.color)
legend(5, 0.6, legend = c("setosa", "versicolor", "virginica"),
       pch = "abc", col = c("red", "blue", "green")
)



# 37/86
plot(1:7, rnorm(7), xaxt = "n", frame = FALSE)
axis(1, 1:7, LETTERS[1:7], col = "green")
axis(3, 1:7, paste("test", LETTERS[1:7]),
     col.axis = "blue", las = 2)
axis(4, lty = 2, lwd = 2, las = 2)

plot(1:8, xaxt = "n",  xlab = "")
axis(1, labels = FALSE)
my.labels <- paste("Label", 1:8, sep = "-")
text(1:8, par("usr")[3] - 0.25, srt = 45, adj = 1,
     labels = my.labels, xpd = TRUE)
mtext(1, text = "X Axis Label", line = 3)

par("usr")



# 38/86
plot(0, xlim = c(0, 14), ylim = c(0, 14), type = "n", 
     xlab = "", ylab = "", main = "Rectangles")
rect(1, 2, 3, 6)
n <- 0:3
rect(5 + n, 5 + n, 6 + 2 * n, 6 + 2 * n, col = rainbow(4), 
     border = n + 1, lwd = 4)

symbols(x = c(2, 6), y = c(2, 6), circles = c(1, 4),
        xlim = c(0, 10), ylim = c(0, 10), bg = c("red", "gray"), 
        xlab = "", ylab = "")



# 39/86
if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")
BiocManager::install("EBImage")

library(EBImage) # (Repositories: BioC Software)
Transformers <- readImage("data/Transformers07.jpg")
(dims <- dim(Transformers))
Transformers
imageData(Transformers)[, , 1]

plot(c(0, dims[1]), c(0, dims[2]), type = 'n', xlab = "", ylab = "")
rasterImage(Transformers, 0, 0, dims[1], dims[2])

#install.packages("jpeg")
library(jpeg)
Transformers <- readJPEG("data/Transformers07.jpg")



# 40/86
data <- iris[, 1]
data[33] <- data[33] * 10
plot(data)
ind <- which(data > 15)
data[ind]
data[ind] <- 5.2
windows()
plot(data)



# 42/86
par(mfrow = c(2, 2))
lapply(1:4, function(x)
  hist(iris[, x], xlim = c(0, 8), ylim = c(0, 30), xlab = "x",
       main = names(iris)[x]))



# 44/86
lab <- names(iris)[1]
title <- paste("Histogram of ", lab)
hist(iris[, 1], main = title, xlab = lab)
range(iris[, 1])
hist(iris[, 1], breaks = seq(3.5, 8.5, length = 50), main = title, 
     xlab = lab)
hist(iris[, 1], breaks = seq(3.5, 8.5, length = 50), main = title,
     xlab = lab, pro = T)



# 47/86
plot(density(iris$Sepal.Length))



# 48/86
hist(iris[, 1], breaks = 15, main = title, xlab = lab, 
     col = "green", pro = T)
lines(density(iris[, 1], width = 0.6, n = 200))



# 50/86
par(mfrow = c(1, 2))
set.seed(12345)

n <- 100
mu <- 0.5
sigma <- 0.15
x <- rnorm(n, mu, sigma)
hist(x, freq = FALSE, ylim = c(0, 3), main = "")
y <- seq(0, 1, length = n)
lines(y, dnorm(y, mu, sigma), type = 'l')
qqnorm(x, main = "rnorm(mu=0.5, sigma=0.15)")

qqline(x)

qqplot(x, rnorm(300))
qqline(x, col = 2)
qqplot(scale(x), rnorm(300))
qqline(scale(x), col = 2)



# 51/86
pie.sales <- c(0.12, 0.3, 0.26, 0.16, 0.04, 0.12)
sum(pie.sales)
names(pie.sales) <- c("Blueberry", "Cherry", "Apple",
                      "Boston Cream", "Other", "Vanilla Cream")

pie(pie.sales) # default colours

pie(pie.sales,
    col = c("purple", "violetred1", "green3", "cornsilk",
            "cyan", "white"))
pie(pie.sales, col = gray(seq(0.4, 1.0, length = 6)))
pie(pie.sales, clockwise = TRUE, main = "pie with clockwise=TRUE")
pie(rep(1, 200), labels = "", col = rainbow(200), border = NA,
    main = "Rainbow Pie")



# 52/86
library(plotrix)
library(survival)
head(veteran)
slices <- summary(veteran$celltype)
p <- floor(100 * slices / sum(slices))
pie3D(slices, labels = paste0(names(slices), " (", p, "%)"),
      explode = 0.1)



# 53/86
xlab <- names(iris)[1]
ylab <- names(iris)[2]
title <- paste(ylab, "against", xlab, " of Iris Data")
x <- iris[, 1]
y <- iris[, 2]
plot(x, y, col = "red", xlab = xlab, ylab = ylab, main = title)

range(x)
range(y)
plot(y ~ x, xlab = xlab, ylab = ylab, xlim = c(1.5, 9), ylim = c(1.5, 9),
     type = "n")
points(x[1:50], y[1:50], col = "red")
points(x[51:100], y[51:100], col = "blue")
points(x[101:150], y[101:150], col = "green")
abline(lm(y ~ x))



# 55/86
curve(x ^ 3 - 3 * x,-2, 2)
curve(sin,-2 * pi, 2 * pi)

weibull <- function(alpha, beta, x) {
  alpha * beta * (x ^ (alpha - 1))
}

b <- c(1, 2, 4, 8)
for (i in 1:length(b)) {
  curve(weibull(0.5, b[i], x), from = 0, to = 2,
    add = (i != 1), col = i, ylim = c(0, 50), main = "alpha=.5")
  }
legend(1.5, 40, legend = b, col = 1:length(b), lty = 1)




# 57/86
par(mfrow = c(1, 4))
names(iris)
attach(iris)
boxplot(Sepal.Length, xlab = "Sepal.Length")
boxplot(Sepal.Length ~ Species, ylab = "Sepal.Length")
names(iris) <- c("SL", "SW", "PL", "PW", "Species")
boxplot(iris[, which(sapply(iris, is.numeric))])
boxplot(iris[, which(sapply(iris, is.numeric))], horizontal = T, col = 2:8)
detach(iris)


# 58/86
data(iris)
means <- tapply(iris$Sepal.Length, iris$Species, mean)
barplot(means, xlab = "Species", ylab = "Mean of Sepal.Length")
# density:  a vector giving the density of shading lines
barplot(means, ylab = "Species", xlab = "Mean of Sepal.Length",
        density = 20, horiz = TRUE)


# 59/86
barplot(VADeaths)
barplot(VADeaths, beside = TRUE, col = 1:5)

barplot(VADeaths, beside = TRUE, 
        col = c("lightblue", "mistyrose", "lightcyan",
                "lavender", "cornsilk"),
        legend = rownames(VADeaths), ylim = c(0, 140))
title(main = "Death Rates in Virginia", font.main = 4)



# 60/86
pairs(iris[, 1:4], col = as.integer(iris[, 5]) + 1)
pairs(iris[, 1:4], col = as.integer(iris[, 5]) + 1, panel = panel.smooth)



# 61/86
sines <- outer(1:20, 1:4, function(x, y)
  sin(x / 20 * pi * y))
dim(sines)
sines
matplot(sines, pch = 1:4, type = "o", col = rainbow(ncol(sines)), 
        main = "ex1")
matplot(sines, pch = 21:23, type = "b", col = 2:5, bg = 2:5, 
        main = "ex2")



# 62/86
data(UKLungDeaths) # total, male, female death
ts.plot(ldeaths, mdeaths, fdeaths,
        xlab = "year", ylab = "deaths", lty = c(1:3))

data(sunspots)
plot(sunspots) # sunspots is ts class
class(sunspots)
is.ts(sunspots)



# 63/86
cell.raw <- read.table("data/trad_alpha103.txt",
                       row.names = 1, header = T)
head(cell.raw)
cell.xdata <- t(scale(t(cell.raw[, 2:19]), center = T, scale = T))
y.C <-  as.integer(cell.raw[, 1])
table(y.C)
no.cluster <- length(unique(y.C))
p <- ncol(cell.raw) - 1
cellcycle.color <- c("darkgreen", "blue", "red", "gray50", "orange")
ycolors <- cellcycle.color[y.C + 1]
my.pch <- c(1:no.cluster)[y.C + 1]
phase <- c("G1", "S", "S/G2", "G2/M", "M/G1")
matplot(t(cell.xdata), lty = 1, type = "l", ylab = "gene expression",
        col = ycolors, xlab = "time", main = "Time series", xaxt = "n")
time.label <- parse(text = paste("t[", 0:p, "]", sep = ""))
axis(1, 1:(p + 1), time.label)
legend("bottom", legend = phase, col = cellcycle.color, 
       lty = 1, horiz = T, lwd = 2)



# 64/86
plot(1)
locations <- locator(6)
polygon(locations, col = "lavender")

xv <- seq(-3, 3, 0.01)
yv <- dnorm(xv)
plot(xv, yv, type = "l")

polygon(c(xv[xv <= -1]), c(yv[xv <= -1]), col = "blue")

plot(xv, yv, type = "l")
polygon(c(xv[xv <= -1],-1), c(yv[xv <= -1], yv[xv == -3]), col = "red")



# 65/86
scores <- data.frame(
  row.names = c("Student.1", "Student.2", "Student.3"),
  Biology = c(7.9, 3.9, 9.4),
  Physics = c(10, 20, 0),
  Maths = c(3.7, 11.5, 2.5),
  Sport = c(8.7, 20, 4),
  English = c(7.9, 7.2, 12.4),
  Geography = c(6.4, 10.5, 6.5),
  Art = c(2.4, 0.2, 9.8),
  Programming = c(0, 0, 20),
  Music = c(20, 20, 20)
)
scores

max.min <- data.frame(
  Biology = c(20, 0),
  Physics = c(20, 0),
  Maths = c(20, 0),
  Sport = c(20, 0),
  English = c(20, 0),
  Geography = c(20, 0),
  Art = c(20, 0),
  Programming = c(20, 0),
  Music = c(20, 0)
)
rownames(max.min) <- c("Max", "Min")
max.min

mydata <- rbind(max.min, scores)
mydata

library(fmsb)
student1.data <- mydata[c("Max", "Min", "Student.1"),]
student1.data
radarchart(student1.data)



# 66/86
ploy <- function(x, y) {
  x ^ 2 - x * y + y ^ 2
}
x.grid <- seq(-3, 3, length = 50)
y.grid <- seq(-3, 3, length = 50)
z.grid <- outer(x.grid, y.grid, FUN = ploy)
ploy.title <- paste("三維空間散圖\n", "f(x, y) =x^2-xy+y^2")
persp(x.grid, y.grid, z.grid, main = ploy.title)



# 67/86
library(scatterplot3d)
z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
scatterplot3d(x, y, z, highlight.3d = TRUE, col.axis = "blue", 
              col.grid = "lightblue", main = "scatterplot3d - 1", pch = 20)



# 68/86
#install.packages("plot3D")
library("plot3D")

x <- iris$Sepal.Length
y <- iris$Sepal.Width
z <- iris$Petal.Length
w <- iris$Petal.Width
s <- iris$Species

par(mfrow = c(1, 3), mai = c(0.3, 0.3, 0.3, 0.3))
scatter3D(x, y, z)
scatter3D(x, y, z, pch = 18, clab = c("Sepal", "Width (cm)"),
          main = "Iris data", 
          xlab = "Sepal.Length", 
          zlab = "Petal.Length",
          ylab = "Sepal.Width")
scatter3D(x, y, z, colvar = as.integer(s), 
          col = "blue", pch = 19, cex = 1)



# 69/86
par(mfrow = c(1, 3), mai = c(0.3, 0.3, 0.2, 0.3))
# grey background with white grid lines
scatter3D(x, y, z, bty = "f", colkey = FALSE, ticktype = "detailed", 
          theta = 0, phi = 60)
# theta: the azimuthal direction, phi: the co-latitude.
scatter3D(x, y, z, bty = "g", pch = 18,
          col = as.integer(s) + 1, ticktype = "detailed",
          colkey = list(at = c(2, 3, 4), side = 1,
                        addlines = TRUE, length = 0.5, width = 0.5,
                        labels = c("setosa", "versicolor", "virginica")))
text3D(x, y, z, labels = as.integer(s), colvar = w, bty = "b2")
# "b2": back panels and grid lines are visible

# hist3D, text3D
# scatter2D(x, y, colvar = z, pch = 16)



# 70/86
library(rgl)
demo(rgl)
open3d()
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x, y)
plot3d(x, y, z, col = rainbow(1000), size = 2)

M <- par3d("userMatrix")
play3d(par3dinterp(userMatrix = list(
  M, rotate3d(M, pi / 2, 1, 0, 0),
  rotate3d(M, pi / 2, 0, 1, 0)
)), duration = 4)



# 71/86
library(rgl)
open3d()
comet <-
  readOBJ(url(
    "http://sci.esa.int/science-e/www/object/doc.cfm?fobjectid=54726"
  ))
class(comet)
str(comet)
shade3d(comet, col = "gray")

# export graphics
rgl.snapshot("test.png")
rgl.postscript("test.pdf", "pdf")



# 72/86
my.data <- matrix(c(1:15), ncol = 3, nrow = 5)
my.data
image(my.data, col = grey(1:15 / 15))
image(t(my.data)[, nrow(my.data):1], col = grey(1:15 / 15))



# 73/86
image(t(as.matrix(iris[, 1:4]))[, 150:1], col = terrain.colors(100))
head(iris[, 1:4])
tail(iris[, 1:4])



# 74/86
library(pheatmap)
DESeq_subset <- read.csv("data/DESeq_subset.csv")
dim(DESeq_subset)
head(DESeq_subset)
DESeq.X <- as.matrix(DESeq_subset[, 2:ncol(DESeq_subset)])
colnames(DESeq.X)
rownames(DESeq.X) <- DESeq_subset[, 1]
dimnames(DESeq.X)
str(DESeq.X)
pheatmap(DESeq.X)


DESeq.X.std <- t(apply(DESeq.X, 1, scale))
class(DESeq.X.std)
dimnames(DESeq.X.std) <- dimnames(DESeq.X)
pheatmap(DESeq.X.std) # note the color spectrum



# 75/86
sample.group <-
  data.frame(cell = rep(c("tumour", "normal"), c(4, 2)),
             gender = sample(c("male", "female"), 6, replace =
                               T))
row.names(sample.group) <- colnames(DESeq.X)
sample.group

gene.cluster <-
  data.frame(KMcluster = as.character(kmeans(DESeq.X.std, 2)$cluster))
row.names(gene.cluster) <- rownames(DESeq.X)
head(gene.cluster)


pheatmap(DESeq.X.std,
         annotation_row = gene.cluster,
         annotation_col = sample.group)

pheatmap(
  DESeq.X.std,
  annotation_row = gene.cluster,
  annotation_col = sample.group,
  cutree_rows = 4,
  cutree_cols = 2
)



# 78/86
library(networkD3)
src <- c("A", "A", "A", "A", "B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
networkData <- data.frame(src, target)
simpleNetwork(networkData)



# 81/86
URL <- paste0(
  "https://cdn.rawgit.com/christophergandrud/networkD3/",
  "master/JSONdata/energy.json"
)
Energy <- jsonlite::fromJSON(URL)
str(Energy)
lapply(Energy, head)



# 81/86
Energy



# 83/86
sankeyNetwork(
  Links = Energy$links,
  Nodes = Energy$nodes,
  Source = "source",
  Target = "target",
  Value = "value",
  NodeID = "name",
  fontSize = 12,
  nodeWidth = 30
)



# 84/86
require(devtools)
install_github("lchiffon/wordcloud2")
library(wordcloud2)
head(demoFreq)
tail(demoFreq)
str(demoFreq)
wordcloud2(data = demoFreq)
