교수님, 안녕하세요.
다름이 아니라 sphagetti plot을 그리려고 하는데 잘되지가 않아서 문의드립니다.
환자의 경과에 따른 혈압변화를 나타내고자 sphagetti plot을 그리려고합니다.
가능할지요.....
Comment 3
-
cardiomoon
2019.07.23 08:29
-
cardio_H
2019.07.23 09:04
위의 파일은 이런 그래프를 그리고 싶어 올린 예시 그래프입니다.
-
shanmdphd
2019.08.14 11:21
이렇게 하면 어떨까요?
# setup ----
library(tidyverse)
library(lubridate)
df <- read.csv('AMI_registry_BP.csv', as.is=TRUE) %>%
as_tibble()
tidy_df <- function(df, column = 'Date', subtext) {
df %>%
select(id, starts_with(column)) %>%
gather(visit, column, -id) %>%
filter(grepl('[0-9]$', visit)) %>%
mutate(visit = sub(subtext, '', visit) %>% as.numeric)
}
# combine all data ----
df_raw <- left_join(tidy_df(df, 'Date', 'Date_') %>% rename(date = column),
tidy_df(df, 'SBP', 'SBP_') %>% rename(sbp = column),
by = c('id', 'visit')) %>%
left_join(tidy_df(df, 'DBP', 'DBP_') %>% rename(dbp = column),
by = c('id', 'visit')) %>%
mutate(date = lubridate::ymd(date)) %>%
filter(!is.na(date) & !is.na(sbp) & !is.na(dbp)) %>%
print()
# cleaning strange data ----
df_final <- df_raw %>%
filter(!id %in% (df_raw %>% filter(sbp > 300) %>% .$id)) %>%
filter(!id %in% (df_raw %>% filter(dbp > 200) %>% .$id))
# SBP plot ----
df_final %>%
ggplot(aes(date, sbp, group = id)) +
geom_line(alpha = 0.1) +
theme_bw()
ggsave('systolic-bp.png')
# DBP plot ----
df_final %>%
ggplot(aes(date, dbp, group = id)) +
geom_line(alpha = 0.1) +
theme_bw()
ggsave('diastolic-bp.png')
Back-calculated age와 Back-calculated length가 뭐지요?