0.1 Document Meta Info

  • 분석 데이터는 다음과 같습니다.
    • footfall COP(X), walkway COP(O) from GaitRite for patients with dizziness(BENIGN PAROXYSMAL POSITIONAL VERTIGO; BPPV, 양성 돌발성 두위 현훈증)
    • COP데이터는 GAITRite device에서 추출되었습니다. 이 자료에는 두 가지 데이터가 혼재되어 있습니다. 하나는 전체 보행의 COP trajectory data가 있고, 또 하나는 족부의 COP변화 데이터가 있습니다. 첫번째 데이터는 각 참가자의 COP 파일 마지막 부분에 998이라는 번호로 인덱스되어 있습니다.
    • basic gait data-spss file.
      • 김oo 교수님이 데이터 분석하다 변형시킨 데이터(BPPV_basicGait_n33-ver2.sav)가 있고,
      • 처음에 임용현 박사가 제작한 basic gait data가 있습니다(BPPV_basicGait_n33.sav).
  • 본 연구에서 환자는 walkway를 두 번 걸었기 때문에, 사전 2회기/치료후 2회기(1인당 ‘.csv’ 파일이 총 4개 있어야 합니다.)
  • concrete Goals:
    • BPPV 환자들의 보행검사 결과 중 Center of Pressure를 시각화 합니다.
    • 기본 보행 데이터 중에서 의미있는 데이터를 시각화합니다.
  • R-studio version: 이 문서의 하단부에 Sessioninfo()를 명시할 예정입니다.
  • markdown 문서 최종 업데이트:
    • 2020-11-18일 15시 58분.
    • 연구실 Dell 컴퓨터로 최종 작성되었습니다.
    • 최종적으로 논문에 쓸 그림은 Final selection: 섹션들을 참조하면 됩니다.

0.2 코드 실행 전 확인사항

  • 작업디렉토리 지정이 매우 복잡할 수 있습니다. 현재 저의 작업 환경이 맥북프로 OS, Dell 윈도우10 OS, MS 서피스프로 윈도우10으로 나뉘어져 있고, 이 상이한 작업 환경을 Dropbox를 통해 연결하고 있습니다.
  • 따라서 어디서 다시 분석하느냐에 따라 작업디렉토리 지정은 달라져야 합니다.
  • 기본적으로 이 시각화 코드의 완성은 Macbook Pro에서 이루어졌습니다.
  • 데이터 경로는 setwd(“C:/Users/jangg/Dropbox/DellWorks/Doc/Rprojects/BPPV Gait visualization/data/cop coordinates data”)입니다.

0.3 분석환경이 달라진다면 수정할 항목

0.4 library import

  • load_libraries를 명시하면 마크다운 문서 모든 영역에서 패키지를 적용할 수 있습니다.
library("dplyr")
library("ggplot2")
library("ggpubr")
library("haven")

0.5 COP data path

# COP 원시 파일이 존재하는 경로 
data_path <- c("/Users/tigris/Dropbox/DellWorks/Doc/Rprojects/BPPV gait visualization/data/cop coordinates data")
  • 기본적인 작업폴더는 .Rmd 파일이 있는 폴더입니다.

  • 작업폴더를 새롭게 지정하기 위해서는 setwd("C:/Users/jangg/Dropbox/DellWorks/Doc/Rprojects/BPPV Gait visualization/) 이렇게 적용하면 됩니다.

  • 경로 설정 변경

    • 컴퓨터에 따라 경로 설정을 변경해야 합니다.
    • 이것은 추후 매우 중요한 부분입니다.
    • 몇 달 혹은 몇 년 후에도 동일한 분석환경일 수 없습니다.
    • 따라서 운영체제나 분석환경(Rstudio or VScode etc.)이 달라질 수 있는 조건을 염두하고 코드를 짜야 합니다.
  • 윈도우 컴퓨터 폴더 경로

    • data_path <- c("C:/Users/jangg/Dropbox/DellWorks/Doc/Rprojects/BPPV Gait visualization/data/cop coordinates data")
  • 맥북 경로

    • data_path <- c("/Users/tigris/Dropbox/DellWorks/Doc/Rprojects/BPPV gait visualization/data/cop coordinates data")
  • ~/BPPV gait visualization/data/cop coordinates data는 미리 만들어져 있어야 하고, 데이터가 존재해야 합니다.

0.6 output data path 및 폴더 만들기

  • 분석 후 만들어질 데이터 타입 결과물과 그림 타입 결과물을 저장할 공간을 만들고, 그 경로를 저장합니다.
wd <- getwd()

ydtm <- format(Sys.time(), "%y%m%d%H%M") # current year, month, day, time, minute

dir.create(paste(wd, "/", "outputs", "_", ydtm, sep=""))   # 결과 폴더 만들기

out.path <- paste(wd, "/", "outputs", "_", ydtm, sep="")  # 결과 폴더의 경로 저장
  • 분석할 때마다 폴더를 새롭게 만들기 위해 년/월/일/시/분을 마지막에 붙입니다.
    • Sys.time()은 마지막에 콜론이 있어 폴더 만들기에 오류가 나게 됩니다. 예) “2020-11-18 13:00:28 KST”
    • 따라서 새로운 객체에 format()을 이용하여 저장하면 됩니다. ydtm <- format(Sys.time(), "%y%m%d%H%M")
    • %Y는 년도 4자리, %y는 년도 2자리만 표시합니다.
  • 따라서 새롭게 마크다운을 컴파일하여도 컴파일 날짜와 함께 만들어져 이후에 편리합니다.

0.7 분석시작: COP data import

  • 탐색 파일 : 각 개인폴더 내에 있는 분석결과 파일 중 COPdata.csv들을 모두 수집합니다.
# 데이터가 있는 상위 폴더가 작업폴더로 설정되어야 함. 
listCOP <- list.files(recursive=TRUE, pattern="COPdata.csv")  

for(i in 1:length(listCOP)){       
  COP <- read.csv(listCOP[i], sep=",", header=TRUE)
  in.data <- COP
  write.table(in.data, paste(out.path,"/", "COP.txt", sep=""),sep=",", row.names=FALSE, col.names = FALSE, append = TRUE)
}

sa <- read.table(paste(out.path, "COP.txt", sep="/"), sep=",", header=FALSE)
write.csv(sa, paste(out.path, "COP.csv", sep="/")) # 반복측정에서 treatment(2) -> trial(2) 순서로 입력
junk <- paste(out.path,"/", "COP.txt", sep="") #삭제할 경로와 파일
file.remove(junk)  # 파일삭제
## [1] TRUE
  • listCOP <- list.files(recursive=TRUE, pattern="COPdata.csv") 이 명령문이 제대로 작동하기 위해서는 Knit에서 Knit DirectoryCurrent Working Directory로 체크되어 있어야 합니다.
  • 그렇지 않고 잘 작동하지 않는다면, 작업폴더 지정을 이 코드 구역 내에서 따로 해야 합니다.
  • 데이터의 양이 많아서 이 부분에서 시간이 오래 걸립니다.

0.8 COP point plot 그리기

  • 총 35명의 데이터 중, 33명의 COP 값을 왼쪽에서 오른쪽 걷기와 오른쪽에서 왼쪽으로 걷기, 치료 전/치료 후로 그림을 그립니다.
  • 원시 데이터의 패턴을 확인하고 이 데이터의 패턴을 어떻게 표현할 지 고민해 본다.
  • 탐색을 위해 그렸습니다. 실제로 논문에 사용하지는 않습니다.
# left to right direction walking (before-treatment)
fig_1 <- ggplot(sa, aes(x = V3, y = V4)) +
 geom_point(na.rm = FALSE, show.legend = NA, alpha=0.1) +
 xlim(0, 400) +
 ylim(0, 40)

# left to right direction walking (post-treatment)
fig_2 <- ggplot(sa, aes(x = V7, y = V8)) +
 geom_point(na.rm = FALSE, show.legend = NA, alpha=0.1) +
 xlim(0, 400) +
 ylim(0, 40)

# right to left direction walking (before-treatment)
fig_3 <- ggplot(sa, aes(x = V5, y = V6)) +
 geom_point(na.rm = FALSE, show.legend = NA, alpha=0.1) +
 xlim(0, 400) +
 ylim(0, 40)

# right to left direction walking (post-treatment)
fig_4 <- ggplot(sa, aes(x = V9, y = V10)) +
 geom_point(na.rm = FALSE, show.legend = NA, alpha=0.1) +
 xlim(0, 400) +
 ylim(0, 40)

ggarrange(fig_1, fig_2, fig_3, fig_4, labels = c("A","B","C","D"), ncol = 2, nrow = 2)

+ ggarrange함수는 ggpubr패키지에서 불러왔습니다.

0.9 example_1: 실제 COP 데이터를 이용한 density plot

  • 의도적으로 그림 4개의 옵션을 다르게 조정해 보았습니다.
  • 옵션조정하는 연습을 하기 위함입니다.
  • 데이터 스무딩을 통하여 트렌드를 읽을 수 있게 하였습니다(geom_smooth(span = 0.72)).
  • 그러나 트렌드는 큰 의미가 없는 것 같네요.
# You can also call the palette using a name.
x_1 <- ggplot(sa, aes(x=V3, y=V4) ) +
  stat_density_2d(aes(fill = ..density..),geom = "raster", contour = FALSE) +
  scale_fill_distiller(palette= "Spectral", direction=-1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  geom_smooth(span = 0.72) +
  theme(legend.position='none') +
  theme_minimal() # x와 y축이 선으로 확장되어 보입니다.


x_2 <- ggplot(sa, aes(x=V7, y=V8) ) +
  stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
  scale_fill_distiller(palette= "Spectral", direction=-1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  geom_smooth(span = 0.72) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  theme(legend.position='none')

# You can also call the palette using a name.
x_3 <- ggplot(sa, aes(x=V5, y=V6) ) +
  stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
  scale_fill_distiller(palette= "Spectral", direction=-1) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  geom_smooth(span = 0.72) +
  theme(legend.position='none')

x_4 <- ggplot(sa, aes(x=V9, y=V10) ) +
  stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
  scale_fill_distiller(palette= "Spectral", direction=-1) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  geom_smooth(span = 0.72) +
  theme(legend.position='none')

COPraster <- ggarrange(x_1, x_2, x_3, x_4, labels = c("A", "B", "C", "D"), ncol = 2, nrow = 2)
COPraster

ggsave("COPrasterdensity.png", COPraster, dpi=300, width = 30, height = 20, units = "cm", scale = 0.8, path=out.path)
  • raster는 타일형태로 밀도를 표현하는 것입니다. 따라서 이 옵션을 선택하면 부드러운 윤곽선을 그릴 수는 없습니다.
  • 즉, geom = "raster", contour = FALSE에서 raster를 썼다면 contour=TRUE로는 쓸 수 없습니다.
  • 이 코드로 표현된 것들 또한 예제입니다.
  • 그림의 축조정에 대한 미묘한 옵션들이 있습니다.
    • theme_minimal()은 x와 y축이 선으로 보이게 합니다. 이게 없을 경우, 회색 배경의 상자가 보입니다.
    • scale_x_continuous(expand = c(0, 0))scale_y_continuous(expand = c(0, 0))은 설정한 축(xlim or ylim)만큼 그림의 틀을 확장하는 효과를 나타냅니다.
  • ggsave()에서 path=out.path를 코딩하면 output folder에 결과가 저장됩니다.

0.10 example_2: 레이어 추가 방식으로 그려보기

  • 최종 결과물의 질을 높이기 위해 방식을 바꿔가며 그려 봅니다.
m <- ggplot(sa, aes(x=V3, y=V4))
m + geom_density_2d()

m + geom_density_2d_filled(alpha = 0.5)

m + geom_density_2d_filled(alpha = 0.5) +
  geom_density_2d(size = 0.25, colour = "black")

m + geom_density_2d_filled(contour_var = "count")

m + stat_density_2d(contour_var = "ndensity") + 
  geom_density_2d_filled(contour_var = "ndensity") 

  • 이 방식이 효율적인 것 같습니다. 그러나 시간이 없어서 여기서 적용은 어려울 것 같네요.
  • contour_var = 은 3가지 method가 있습니다(count/density/ndensity).
  • BPPV 환자의 치료 전후 밀도의 변화는 비교를 위하여 ndensity 방식을 써야할 것 같습니다.

0.11 example_3: 색상과 윤곽선을 동시에 그려 보기

# You can also call the palette using a name.
pp_1 <- ggplot(sa, aes(x=V3, y=V4) ) +
  stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
  stat_density_2d(geom = "density_2d", position = "identity", contour = TRUE, contour_var = "density")+
  scale_fill_distiller(palette= "Spectral", direction=-1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

pp_2 <- ggplot(sa, aes(x=V7, y=V8) ) +
  stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
  stat_density_2d(geom = "density_2d", position = "identity", contour = TRUE, contour_var = "density")+
  scale_fill_distiller(palette= "Spectral", direction=-1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

pp_3 <- ggplot(sa, aes(x=V5, y=V6) ) +
  stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
  stat_density_2d(geom = "density_2d", position = "identity", contour = TRUE, contour_var = "density")+
  scale_fill_distiller(palette= "Spectral", direction=-1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

pp_4 <- ggplot(sa, aes(x=V9, y=V10) ) +
  stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
  stat_density_2d(geom = "density_2d", position = "identity", contour = TRUE, contour_var = "density")+
  scale_fill_distiller(palette= "Spectral", direction=-1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

ContOnden <- ggarrange(pp_1, pp_2, pp_3, pp_4, labels=c("A", "B", "C", "D"), ncol = 2, nrow = 2)
ContOnden

ggsave("COPcontourOndensity.png", ContOnden, dpi=300, width = 30, height = 20, units = "cm", scale = 0.8, path=out.path)
  • 아무래도 가시성이 떨어지는 것 같습니다. 예쁘지도 않고 정보도 복잡해 보입니다.
  • 그러나 density legend가 다른 것들과는 다르게 표현됩니다.
  • 왜 그럴까요?

0.12 example_4: density plot with points

  • countmethod 사용하여 분석하고 그 밀도 그림 위에 데이터를 점으로 표현합니다.
fig_1 <- ggplot(sa, aes(x = V3, y = V4)) +
 geom_point() +
 xlim(0, 400) +
 ylim(0, 40)

fig_2 <- ggplot(sa, aes(x = V7, y = V8)) +
 geom_point() +
 xlim(0, 400) +
 ylim(0, 40)

fig_3 <- ggplot(sa, aes(x = V5, y = V6)) +
 geom_point() +
 xlim(0, 400) +
 ylim(0, 40)

fig_4 <- ggplot(sa, aes(x = V9, y = V10)) +
 geom_point() +
 xlim(0, 400) +
 ylim(0, 40)

f1 <- fig_1 +  
  geom_density_2d_filled(contour_var = "count")  + 
  geom_point(alpha=0.10, colour = "white")

f2 <- fig_2 +  
  geom_density_2d_filled(contour_var = "count")  + 
  geom_point(alpha=0.10, colour = "white")

f3 <- fig_3 +  
  geom_density_2d_filled(contour_var = "count")  + 
  geom_point(alpha=0.10, colour = "white")

f4 <- fig_4 +  
  geom_density_2d_filled(contour_var = "count")  + 
  geom_point(alpha=0.10, colour = "white")
  # geom_density_2d_filled(contour_var = "ndensity")
  # geom_density_2d_filled(contour_var = "density")
  # geom_density_2d_filled(contour_var = "ndensity")

figarrange <- ggarrange(f1, f2, f3, f4,labels = c("A","B","C","D"), ncol = 2, nrow = 2, common.legend = TRUE)

figarrange

ggsave("COPpointOndensity.png", figarrange, dpi=300, width = 30, height = 20, units = "cm", scale = 0.8, path=out.path)
  • 여기서 density level의 의미가 와닿지 않습니다.
  • 메뉴얼에 설명도 자세하지 않아 이해하기가 어렵네요. 추후 관심을 갖고 찾아야 합니다.

0.13 example_5: COP를 점으로만 그려보기

  • 이해를 돕기 위해 점으로만 그려봅니다.
  • 논문에 사용하진 않습니다.
fig_1 <- ggplot(sa, aes(x = V3, y = V4)) +
 geom_point(alpha=0.1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal() 

fig_2 <- ggplot(sa, aes(x = V7, y = V8)) +
 geom_point(alpha=0.1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

fig_3 <- ggplot(sa, aes(x = V5, y = V6)) +
 geom_point(alpha=0.1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

fig_4 <- ggplot(sa, aes(x = V9, y = V10)) +
 geom_point(alpha=0.1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

pointarrange <- ggarrange(fig_1, fig_2, fig_3, fig_4,labels = c("A","B","C","D"), ncol = 2, nrow = 2,common.legend = TRUE, legend = "right")
pointarrange

ggsave("COP_point.png", pointarrange, dpi=300, width = 30, height = 20, units = "cm", scale = 0.8, path=out.path)

0.14 example_6:

  • countmethod 사용하여 분석
p_1 <- ggplot(sa, aes(x = V3, y = V4)) +
 geom_point() +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal() 

p_2 <- ggplot(sa, aes(x = V7, y = V8)) +
 geom_point() +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

p_3 <- ggplot(sa, aes(x = V5, y = V6)) +
 geom_point() +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

p_4 <- ggplot(sa, aes(x = V9, y = V10)) +
 geom_point() +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

p1 <- p_1 +  
  geom_density_2d_filled(contour_var = "count")+
  labs(x = "AP direction(Left to Right, cm)", y = "ML direction, cm")

p2 <- p_2 +  
  geom_density_2d_filled(contour_var = "count")+
  labs(x = "AP direction(Left to Right, cm)", y = "ML direction, cm")

p3 <- p_3 +  
  geom_density_2d_filled(contour_var = "count")+
  labs(x = "AP direction(Right to Left, cm)", y = "ML direction, cm")

p4 <- p_4 +  
  geom_density_2d_filled(contour_var = "count")+
  labs(x = "AP direction(Right to Left, cm)", y = "ML direction, cm")


picarrange <- ggarrange(p1, p2, p3, p4,labels = c("A","B","C","D"), ncol = 2, nrow = 2,common.legend = TRUE, legend = "right")
picarrange

ggsave("COP_count.png", picarrange, dpi=300, width = 30, height = 20, units = "cm", scale = 0.8, path=out.path)
  • count method를 사용하여 그렸습니다. 앞선 그림들과 비교해 보기 위해 그런 것입니다.
  • 어떤 방식이 COP 데이터의 밀도를 가장 잘 표현할 수 있을까 고민한 흔적입니다.

0.15 Final selection: COP의 밀도

  • ndensity method 사용하여 분석하고 논문에 삽입합니다.
fig_1 <- ggplot(sa, aes(x = V3, y = V4)) +
 geom_point(alpha=0.1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal() 

fig_2 <- ggplot(sa, aes(x = V7, y = V8)) +
 geom_point(alpha=0.1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

fig_3 <- ggplot(sa, aes(x = V5, y = V6)) +
 geom_point(alpha=0.1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

fig_4 <- ggplot(sa, aes(x = V9, y = V10)) +
 geom_point(alpha=0.1) +
  xlim(-50, 450) +
  ylim(-5, 45) +
  theme(legend.position='none')+
  theme_minimal()

f1 <- fig_1 +  
  geom_density_2d_filled(contour_var = "ndensity")+
  labs(x = "", y = "")
  # geom_point(alpha=0.10, colour = "white")
  # geom_density_2d_filled(contour_var = "ndensity")
  # geom_density_2d_filled(contour_var = "density")
  # geom_density_2d_filled(contour_var = "ndensity")

f2 <- fig_2 +  
  geom_density_2d_filled(contour_var = "ndensity")+
  labs(x = "", y = "")

f3 <- fig_3 +  
  geom_density_2d_filled(contour_var = "ndensity")+
  labs(x = "", y = "")

f4 <- fig_4 +  
  geom_density_2d_filled(contour_var = "ndensity")+
  labs(x = "", y = "")

figarrange <- ggarrange(f1, f2, f3, f4,labels = c("A","B","C","D"), ncol = 2, nrow = 2, common.legend = TRUE, legend = "right")
figarrange

ggsave("COP_ndensity.png", figarrange, dpi=300, width = 30, height = 20, units = "cm", scale = 0.8, path=out.path)
  • geom_density_2d_filled에서 ndensity 방식으로 그려봅니다.
  • 하지만 코딩이 개판이네요.
  • 단순화하고, 이해하기 쉽게 짤 필요가 있습니다.

0.16 Final selection: Gait variability 시각화

  • 논문에 삽입합니다.
  • 가장 대표적인 parameter를 몇 개 골라 표현합니다.
# 윈도우용 경로: 만약 맥북에서 분석한다면 이 부분을 바꿔줘야 합니다. 
basic_gait <- read_sav("C:/Users/jangg/Dropbox/DellWorks/Doc/Rprojects/BPPV gait visualization/data/BPPV_basicGait_n33-ver2.sav")

# 두 발을 평균
pre_ST_CV <- data.frame((basic_gait$CV_ST_left+basic_gait$CV_ST_right)/2)
pre_SL_CV <- data.frame((basic_gait$CV_SL_left+basic_gait$CV_SL_right)/2)
pos_ST_CV <- data.frame((basic_gait$CV_ST_left_a+basic_gait$CV_ST_right_a)/2)
pos_SL_CV <- data.frame((basic_gait$CV_SL_left_a+basic_gait$CV_SL_right_a)/2)

# 변수에 이름 붙이기
names(pre_ST_CV) <- "Before" 
names(pos_ST_CV) <- "After" 
names(pre_SL_CV) <- "Before"
names(pos_SL_CV) <- "After" 

df1 <- cbind(pre_ST_CV, pos_ST_CV)
df2 <- cbind(pre_SL_CV, pos_SL_CV)

# stride length:왼발의 치료 전후 비교
cv_1 <- ggpaired(df1, cond1="Before", cond2 = "After", width=0.3, fill = "condition", palette = "d3", xlab = "", ylab = "Stride Time CV (%)")
cv_2 <- ggpaired(df2, cond1="Before", cond2 = "After", width=0.3, fill = "condition", palette = "d3", xlab = "", ylab = "Stride Length CV (%)")

# cv_1 + theme(legend.position = "none")
# cv_2 + theme(legend.position = "none")

pic_CV <- ggarrange(cv_1, cv_2, labels = c("A","B"), ncol = 2, nrow = 1, common.legend = FALSE, legend = "none")
pic_CV

ggsave("gaitCV.png", pic_CV, dpi=300, width = 30, height = 20, units = "cm", scale = 0.8, path=out.path)
  • 그림을 보면, stride time이 유의하게 감소한 것으로 알 수 있습니다.
  • 그러나 공간 변수인 stride length의 변산성은 줄어들지 않았네요.
  • data 사전처리 방법은 항상 연습해 놓아야 합니다. R을 사용하지 않다가 다시 사용하면 데이터 구조도 머리에 들어오지 않습니다.

0.17 Final selection: basic gait parameters comparison

  • 논문에 삽입합니다.
  • velocity, cadence, FAP score
  • box-dot plot
# 윈도우용 경로: 만약 맥북에서 분석한다면 이 부분을 바꿔줘야 합니다. 
basicGait_2 <- read_sav("C:/Users/jangg/Dropbox/DellWorks/Doc/Rprojects/BPPV gait visualization/data/BPPV_basicGait_n33.sav")

# velocity
vel1 <- basicGait_2[10] #pre left foot 
vel2 <- basicGait_2[92] #pre left foot 
names(vel1) <- "velocity"
names(vel2) <- "velocity"
vel <- data.frame(rbind(vel1, vel2)) # colume name 일치해야 함
vel$treatment <- rep(c("Before", "After"), c(33, 33))

# cadence
cad1 <- basicGait_2[11] #pre left foot 
cad2 <- basicGait_2[93] #pre left foot 
names(cad1) <- "cadence"
names(cad2) <- "cadence"
cad <- data.frame(rbind(cad1, cad2)) # colume name 일치해야 함
cad$treatment <- rep(c("Before", "After"), c(33, 33))

# FAP
fap1 <- basicGait_2[16] #pre left foot 
fap2 <- basicGait_2[98] #pre left foot 
names(fap1) <- "fap"
names(fap2) <- "fap"
fap <- data.frame(rbind(fap1, fap2)) # colume name 일치해야 함
fap$treatment <- rep(c("Before", "After"), c(33, 33))

theme_set(theme_classic2())

# velocity
g <- ggplot(vel, aes(treatment, velocity))
ph1 <- g + geom_boxplot(width=0.3) + 
  geom_dotplot(binaxis='y', stackdir='center', 
               dotsize = .6, 
               fill="red") +
  scale_x_discrete(limits = c("Before", "After")) 

# cadence
c <- ggplot(cad, aes(treatment, cadence))
ph2 <- c + geom_boxplot(width=0.3) + 
  geom_dotplot(binaxis='y', stackdir='center', 
               dotsize = .6, 
               fill="red") +
  scale_x_discrete(limits = c("Before", "After")) 

# fap
c <- ggplot(fap, aes(treatment, fap))
ph3 <- c + geom_boxplot(width=0.3) + 
  geom_dotplot(binaxis='y', stackdir='center', 
               dotsize = .6, 
               fill="red") +
  scale_x_discrete(limits = c("Before", "After")) 


nagait <- ggarrange(ph1, ph2, ph3, labels = c("A","B", "C"), ncol = 3, nrow = 1, common.legend = FALSE, legend = "none")
nagait

ggsave("basicgait.png", nagait, dpi=300, width = 25, height = 10, units = "cm", scale = 0.8, path=out.path)

끝. 2020-11-18일 15시 49분. 임용현.

sessionInfo()
## R version 3.6.3 (2020-02-29)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19041)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=Korean_Korea.949  LC_CTYPE=Korean_Korea.949   
## [3] LC_MONETARY=Korean_Korea.949 LC_NUMERIC=C                
## [5] LC_TIME=Korean_Korea.949    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] haven_2.2.0   ggpubr_0.2.5  magrittr_1.5  ggplot2_3.3.2 dplyr_1.0.0  
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.4.6       RColorBrewer_1.1-2 pillar_1.4.4       compiler_3.6.3    
##  [5] forcats_0.5.0      tools_3.6.3        digest_0.6.25      viridisLite_0.3.0 
##  [9] lattice_0.20-41    nlme_3.1-147       evaluate_0.14      lifecycle_0.2.0   
## [13] tibble_3.0.1       gtable_0.3.0       mgcv_1.8-31        pkgconfig_2.0.3   
## [17] rlang_0.4.6        Matrix_1.2-18      ggsci_2.9          yaml_2.2.1        
## [21] xfun_0.13          gridExtra_2.3      withr_2.2.0        stringr_1.4.0     
## [25] knitr_1.28         generics_0.0.2     vctrs_0.3.1        hms_0.5.3         
## [29] isoband_0.2.1      grid_3.6.3         tidyselect_1.1.0   cowplot_1.0.0     
## [33] glue_1.4.1         R6_2.4.1           rmarkdown_2.1      tidyr_1.1.0       
## [37] readr_1.3.1        purrr_0.3.4        farver_2.0.3       splines_3.6.3     
## [41] MASS_7.3-51.5      scales_1.1.1       ellipsis_0.3.0     htmltools_0.4.0   
## [45] colorspace_1.4-1   ggsignif_0.6.0     labeling_0.3       stringi_1.4.6     
## [49] munsell_0.5.0      crayon_1.3.4