home
HomeSearchDr. Hain Clinic website Information for Dizzy Patients MusicFLWVarious and Sundry

Dr. Hain's various/sundry has helpful information about things that Dr. Hain has discovered by trial and error.

A time series of PTA (pure tone average) as a bar plot

Step 1: Restructure data

First we have to restructure our "wide" data to produce "long" data. This page shows how to do it for PTA.

This is what our long data looks like:

Long data

Step 2: Create a bar plot of PTA values using ggplot2

In R, there are 4 (yes 4) graphics systems. "Base" graphics are quick/dirty. There are 3 others, but we will focus on ggplot2.

PTA bar plot

This graph was produced using the following R code:

p<-ggplot(data=audio_sep, aes(x=DOS, y=value, fill=side)) +
geom_bar(stat="identity") +
scale_y_reverse(limits=c(100,0), breaks=seq(0,100,10) )+
labs(x="Date", y="dB") +
# geom_line()+ ## Draws lines between bars (not very useful).
# theme_minimal() + ## no box
theme_bw()+ ## puts box around plot.
facet_grid(side ~.) + ## When turned on, converts into two graphs.
# ggtitle(paste("PTA by ear for ", audio$LastName[1])) +
ggtitle("PTA for example data") +
scale_fill_manual(values=c("blue", "red"))
p

 

© Copyright May 3, 2021 , Timothy C. Hain, M.D. All rights reserved.
Dr Hain's CV Clinic dizziness-and-hearing.com FLW Various and Sundry Dr. Hain's CV