-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvisualization draft .Rmd
117 lines (102 loc) · 3.54 KB
/
visualization draft .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
110
111
112
113
114
115
---
title: "R Notebook"
output:
pdf_document: default
html_document:
df_print: paged
word_document: default
---
```{r}
devtools::install_github("ricardo-bion/ggradar",
dependencies=TRUE)
```
## one patient risk visualization
```{r}
library(frisk)
sample_size <- 1
# simulate patients data
dd <- data.frame(age=sample(30:70,sample_size,rep=TRUE),
gender=sample(c("M","F"),sample_size,rep=TRUE),
bmi=sample(16:48, sample_size, rep = TRUE),
hdl=sample(10:100,sample_size,rep=TRUE),
chl=sample(100:400,sample_size,rep=TRUE),
sbp=sample(90:200,sample_size,rep=TRUE),
isSbpTreated=sample(c(TRUE,FALSE),sample_size,rep=TRUE),
smoking=sample(c(TRUE,FALSE),sample_size,rep=TRUE),
diabetes=sample(c(TRUE,FALSE),sample_size,rep=TRUE)
)
patient1 <- calc_card_10_one( age=dd$"age",
gender=dd$"gender",
bmi=NA,
cholesterol=dd$"chl",
hdl=dd$"hdl", sbp=dd$"sbp",
is_sbp_under_treatment=dd$"isSbpTreated",
smoking_status=dd$"smoking",
diabetes_status=dd$"diabetes"
)
library(ggplot2)
library(ggradar)
library(scales)
library(dplyr)
library(janitor)
pp <- as.data.frame(patient1) %>%
remove_empty_cols() %>%
subset(select = -c(risk, heart_age))
#Example 1
ggradar(pp,
axis.labels = colnames(pp)[-1],
centre.y = -5,
label.centre.y = TRUE,
grid.min = 0,
grid.mid = 8,
grid.max = 15,
values.radar = c("0", "8", "15"),
grid.line.width = 0.3,
grid.label.size = 4,
gridline.label.offset = 0,
axis.label.size = 3,
axis.line.colour = "gray40",
gridline.max.colour = "black",
plot.legend = TRUE,
legend.text.size = 10,
font.radar = "Arial")
```
### 3D Analysis of the effects hdl, sbp and chl on CVD Risk for 100 patients
```{r}
# install plotly for this to work
library(dplyr)
library(plotly)
library(frisk)
sample_size <- 100
# simulate patients data
sample <- data.frame(age=sample(30:70,sample_size,rep=TRUE),
gender=sample(c("M","F"),sample_size,rep=TRUE),
bmi=sample(16:48, sample_size, rep = TRUE),
hdl=sample(10:100,sample_size,rep=TRUE),
chl=sample(100:400,sample_size,rep=TRUE),
sbp=sample(90:200,sample_size,rep=TRUE),
isSbpTreated=sample(c(TRUE,FALSE),sample_size,rep=TRUE),
smoking=sample(c(TRUE,FALSE),sample_size,rep=TRUE),
diabetes=sample(c(TRUE,FALSE),sample_size,rep=TRUE)
)
# call frisk function case no bmi
patients <-calc_card_10(sample, age="age", gender="gender", cholesterol="chl",
hdl="hdl", sbp="sbp", is_sbp_under_treatment="isSbpTreated",
smoking_status="smoking", diabetes_status="diabetes"
)
#plot the graph
plot_ly(patients, x = ~chl, y = ~sbp, z = ~hdl,
marker = list(color = ~points, colorscale = c('#FFE1A1', '#683531'), showscale = TRUE)) %>%
add_markers() %>%
layout(scene = list(xaxis = list(title = 'cholesterol'),
yaxis = list(title = 'sbp'),
zaxis = list(title = 'hdl')),
annotations = list(
x = 1.13,
y = 1.05,
text = 'Effects of hdl, chl and sbp on CVD Risk',
xref = 'paper',
yref = 'paper',
showarrow = FALSE
))
```