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).

A time series of VHIT gains as a bar plot

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

target=file.choose(new=FALSE) ## interactively pick file.
vhit=read.table(target, header=TRUE, sep=",",stringsAsFactors=FALSE)

 

Vhit Wide Data'

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:

Vhit Gain

Step 2: Create a bar plot of VHIT values vs date using ggplot2

VHIT time series

This graph was produced using the following R code:

library(ggplot2)

target=file.choose(new=FALSE) ## interactively pick file.
vhit=read.table(target, header=TRUE, sep=",",stringsAsFactors=FALSE)

# 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[1])) +
scale_fill_manual(values=c("blue", "red")) +
coord_cartesian(ylim=c(0,1.2)) +
geom_line()

p

Scatterplot (road-kill graph)

Scatter plot of VHIT (roadkill)

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

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

vhit=read.csv("test_vhit2020.csv", header=TRUE, skip=5, sep=",",stringsAsFactors=FALSE)
vhit$L_gain[vhit$L_gain>2] <- NA
vhit$R_gain[vhit$R_gain>2] <- NA

######## Plotting starts here#####################
scatterPlot <-ggplot(vhit,aes(x=L_gain, y=R_gain))+
geom_point(color= "black")+ labs(title="VHIT gains")+ theme(legend.position=c(0,1), legend.justification=c(0,1))

scatterPlot