This is part of our documentation how one can use the "open source" statistics program "R" to display testing data relevant to medicine. The VHIT test is a rapid method of evaluating vestibular function, that lends itself to serial measurements and a time series (as shown below).

## Step 1: Load data -- this loads in a "wide" dataset

target=file.choose(new=FALSE) ## interactively pick file. '

This is a subset of a very "wide" spreadsheet, using the usual formalism of a single row holding data. Not shown are columns "L_gain" and "R_gain", which are the interesting ones.

## Step 2: Restructure restructure our "wide" data to produce "long" data.

## GAIN by date and side
L_gain= data.frame(side=rep("L", length(vhit\$L_gain)), date=as.Date(vhit\$DOS), GAIN=vhit\$L_gain)
R_gain= data.frame(side=rep("R", length(vhit\$R_gain)), date=as.Date(vhit\$DOS), GAIN=vhit\$R_gain)
GAIN=rbind(L_gain,R_gain) # Sticks two data frames together vertically.

This is what our long data looks like: ## Step 2: Create a bar plot of VHIT values vs date using ggplot2 This graph was produced using the following R code:

library(ggplot2)

target=file.choose(new=FALSE) ## interactively pick file.

# This produces a dataframe. We want factors to be the ear(side) and date
# This means we need a dataframe that looks like (these two together)

## GAIN by date and side
L_gain= data.frame(side=rep("L", length(vhit\$L_gain)), date=as.Date(vhit\$DOS), GAIN=vhit\$L_gain)
R_gain= data.frame(side=rep("R", length(vhit\$R_gain)), date=as.Date(vhit\$DOS), GAIN=vhit\$R_gain)
GAIN=rbind(L_gain,R_gain) # Sticks two data frames together vertically.

p<-ggplot(data=GAIN, aes(x=date, y=GAIN, fill=side)) +
geom_bar(stat="identity", position=position_dodge(), width=20) +
facet_grid(side ~.) +
ggtitle(paste("GAIN by ear for ", vhit\$LastName)) +
scale_fill_manual(values=c("blue", "red")) +
coord_cartesian(ylim=c(0,1.2)) +
geom_line()

p This is just a simple scatter plot of all of the VHIT L and R gains.

library(ggplot2)
library(ggplot2)
library(tidyr)