교수님, 안녕하세요.
다름이 아니라 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')
No. | Subject | Author | Date |
---|---|---|---|
1254 | moonbook package mycsv 관련 오류 문의드립니다. [2] | qwetyui | 2023.11.30 |
1253 | logistic regression 명령어 문의드립니다. [2] | 로렌쵸메디치 | 2023.11.22 |
1252 | spss 파일 불러오기. [1] | 통계린 | 2023.11.22 |
1251 | PSM 매칭변수 숫자 관련 문의입니다. [1] | 오하나 | 2023.11.22 |
1250 | Multiple imputation 관련 질문 및, age adjusted incidence rate 관련 질문을 드립니다. | YSKBH | 2023.11.15 |
1249 | semMediation 설치 재문의드립니다 [3] | 마술샘 | 2023.11.11 |
1248 | 안녕하세요. 정회원 문의 [1] | lionking | 2023.11.06 |
1247 | PSM 관련 질문드립니다. | dr. | 2023.11.05 |
1246 | ggplot [1] | 통계린 | 2023.10.30 |
1245 | 정회원 [1] | 통계린 | 2023.10.29 |
1244 | PSM 관련 질문 드립니다. [2] | 로렌쵸메디치 | 2023.10.25 |
1243 | forest plot 그림이 전체가 다 나오지 않습니다. [1] | joyguni | 2023.10.08 |
1242 | PSM caliper default 값 관련 문의드립니다. [1] | Ooppps | 2023.10.05 |
1241 | reliability test tool,,, [1] | FAdavid | 2023.10.05 |
1240 | 정회원 가입 확인 요청드립니다. [1] | osman | 2023.10.03 |
1239 | 생존분석, cox 회귀 관련 기초적인 질문 입니다. | 만니톨 | 2023.09.27 |
1238 | Twang-mnps에서 매칭된 데이터를 추출하는 방법 좀 알려주세요 | Dorocy | 2023.09.26 |
1237 | 영수증 발급을 부탁드립니다. [1] | 규빈어멈 | 2023.09.26 |
1236 | 정회원 확인 [2] | lionking | 2023.09.24 |
1235 | autoReg 에러 문의드립니다 [1] | 소소 | 2023.09.23 |
Back-calculated age와 Back-calculated length가 뭐지요?