generated from jtr13/cctemplate
-
Notifications
You must be signed in to change notification settings - Fork 139
/
data_composition_plot.Rmd
109 lines (87 loc) · 2.96 KB
/
data_composition_plot.Rmd
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Data_Composition_Plot
Xinfu Su and Yihan Wang
```{r, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r package}
library(viridis)
library(hrbrthemes)
library(waterfalls)
library(tidyverse)
```
```{r}
# create a dataset
season <- c(rep("2021-1" , 3) , rep("2021-4" , 3) , rep("2021-7" , 3) , rep("2021-10" , 3) )
condition <- rep(c("Healthy" , "Infected" , "Serious") , 4)
count <- abs(rnorm(12, 100, 1000))
data <- data.frame(season,condition,count)
ggplot(data, aes(fill=condition, y=count, x=season)) +
geom_bar(position="stack", stat="identity")+
scale_fill_viridis(discrete = T, option = "F") +
ggtitle("COVID-19 Seasonal Behavior") +
theme_ipsum()
```
```{r}
ggplot(data, aes(fill=condition, y=count, x=season)) +
geom_bar(position="fill", stat="identity")+
scale_fill_viridis(discrete = T, option = "F") +
ggtitle("COVID-19 Seasonal Behavior") +
theme_ipsum()
```
```{r small multiple}
ggplot(data, aes(fill=condition, y=count, x=condition)) +
geom_bar(position="dodge", stat="identity")+facet_wrap(~season)+
scale_fill_viridis(discrete = T, option = "G")+
theme(legend.position="none") +
ggtitle("COVID-19 Seasonal Behavior")
```
```{r}
ggplot(data, aes(fill=condition, y=count, x=season)) +
geom_bar(position="dodge", stat="identity")+
scale_fill_viridis(discrete = T, option = "G") +
ggtitle("COVID-19 Seasonal Behavior") +
theme_ipsum()
```
```{r}
time <- as.numeric(rep(seq(1,7),each=7))
value <- runif(49, 10, 100)
employ <- rep(LETTERS[1:7],times=7)
data <- data.frame(time, value, employ)
ggplot(data, aes(x=time, y=value, fill=employ))+geom_area()+
geom_area(alpha=0.5, size=0.1, colour="black") +
scale_fill_viridis(discrete = T)+theme_ipsum()+
ggtitle("Daily Income of each Employee")
```
```{r}
data <- data %>%
group_by(time, employ) %>%
summarise(n = sum(value)) %>%
mutate(percentage = n / sum(n))
ggplot(data, aes(x=time, y=percentage, fill=employ)) +
geom_area()+
geom_area(alpha=0.5, size=0.1, colour="white") +
scale_fill_viridis(discrete = T)+theme_ipsum()+
ggtitle("Daily Income of each Employee")
```
```{r}
slices <- c(10,5,2,16,17)
bands <- c('Velvet Underground', 'Beatles', 'Nirvana', 'Pink Floyd', 'Dirty Fingers')
pie(slices, labels = bands, col=rainbow(length(bands)), main='Pie Chart of Bands')
```
```{r}
slices <- c(10,5,2,16,17)
bands <- c('Velvet Underground', 'Beatles', 'Nirvana', 'Pink Floyd', 'Dirty Fingers')
pct <- round(slices/sum(slices)*100)
bands <- paste(bands, pct)
bands <- paste(bands,"%",sep="")
pie(slices, labels=bands,col=rainbow(length(bands)), clockwise = TRUE, main='Pie Chart of Bands With Percentage')
```
```{r}
value <- c(1000, 3000, -2000, 600, -2500)
bands <- c('Velvet Underground', 'Beatles', 'Nirvana', 'Pink Floyd', 'Dirty Fingers')
df <- data.frame(x = bands,y = value)
waterfall(df, calc_total = TRUE, rect_width = 0.3, linetype = 1)
```
```{r}
waterfall(df, fill_by_sign = FALSE, fill_colours = 2:7)
```