-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualization_dashboard.R
67 lines (58 loc) · 2.37 KB
/
visualization_dashboard.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#------------------------
# Visualization dashboard
#------------------------
library(tidyverse)
library(gridExtra)
data(diamonds)
sample <- sample(1:nrow(diamonds), size = 5000, replace = FALSE)
diamonds <- diamonds[sample, ]
# 1. scatterplot
diamond.plot <- ggplot(data=diamonds, aes(x=carat, y=price, colour = clarity))+
geom_point(aes(size = cut))+
labs(title = 'Example of Scatterplot',
subtitle = 'diamonds dataset',
y="price", x="carat") +
theme(axis.text=element_text(size=8),
axis.title=element_text(size=8),
plot.subtitle=element_text(size=10, face="italic", color="darkred"),
panel.background = element_rect(fill = "white", colour = "grey50"),
panel.grid.major = element_line(colour = "grey90"))
# 2. boxplot
diamond.bxplot <- ggplot(diamonds, aes(x = cut, y=price)) +
geom_boxplot(aes(fill = color))+
labs(title = 'Example of Boxplots',
subtitle = 'diamonds dataset',
y="price", x="cut") +
theme(axis.text=element_text(size=8),
axis.title=element_text(size=8),
plot.subtitle=element_text(size=10, face="italic", color="darkred"),
panel.background = element_rect(fill = "white", colour = "grey50"),
panel.grid.major = element_line(colour = "grey90"))
# 3. violin plot
diamond.violinplot <- ggplot(diamonds, aes(x = cut, y=price)) +
geom_violin(aes(fill = color)) +
labs(title = 'Example of Violin plots',
subtitle = 'diamonds dataset',
y="price", x="cut") +
theme(axis.text=element_text(size=8),
axis.title=element_text(size=8),
plot.subtitle=element_text(size=10, face="italic", color="darkred"),
panel.background = element_rect(fill = "white", colour = "grey50"),
panel.grid.major = element_line(colour = "grey90"))
# 4. bar plot
diamond.barpot <- ggplot(diamonds, aes(x = clarity, fill=cut)) +
geom_bar() +
coord_flip() +
labs(title = 'Example of Bar plots',
subtitle = 'diamonds dataset',
y="count", x="cut") +
theme(axis.text=element_text(size=8),
axis.title=element_text(size=8),
plot.subtitle=element_text(size=10, face="italic", color="darkred"),
panel.background = element_rect(fill = "white", colour = "grey50"),
panel.grid.major = element_line(colour = "grey90"))
grid.arrange(diamond.plot, diamond.bxplot,diamond.violinplot, diamond.barpot,
nrow = 2)
#----
# end
#----