library(knitr)
opts_chunk$set(echo = TRUE )

Package install

Packages <- c("tidyverse", "car","tidyr", "dunn.test","onewaytests","FSA")
lapply(Packages, library, character.only = TRUE)
## -- Attaching packages --------------------------------------------------------------------------------------------------- tidyverse 1.3.0 --
## √ ggplot2 3.2.1     √ purrr   0.3.3
## √ tibble  2.1.3     √ dplyr   0.8.3
## √ tidyr   1.0.0     √ stringr 1.4.0
## √ readr   1.3.1     √ forcats 0.4.0
## -- Conflicts ------------------------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following object is masked from 'package:purrr':
## 
##     some
## ## FSA v0.8.26. See citation('FSA') if used in publication.
## ## Run fishR() for related website and fishR('IFAR') for related book.
## 
## Attaching package: 'FSA'
## The following object is masked from 'package:car':
## 
##     bootCase
## [[1]]
##  [1] "forcats"   "stringr"   "dplyr"     "purrr"     "readr"     "tidyr"    
##  [7] "tibble"    "ggplot2"   "tidyverse" "knitr"     "stats"     "graphics" 
## [13] "grDevices" "utils"     "datasets"  "methods"   "base"     
## 
## [[2]]
##  [1] "car"       "carData"   "forcats"   "stringr"   "dplyr"     "purrr"    
##  [7] "readr"     "tidyr"     "tibble"    "ggplot2"   "tidyverse" "knitr"    
## [13] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"  
## [19] "base"     
## 
## [[3]]
##  [1] "car"       "carData"   "forcats"   "stringr"   "dplyr"     "purrr"    
##  [7] "readr"     "tidyr"     "tibble"    "ggplot2"   "tidyverse" "knitr"    
## [13] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"  
## [19] "base"     
## 
## [[4]]
##  [1] "dunn.test" "car"       "carData"   "forcats"   "stringr"   "dplyr"    
##  [7] "purrr"     "readr"     "tidyr"     "tibble"    "ggplot2"   "tidyverse"
## [13] "knitr"     "stats"     "graphics"  "grDevices" "utils"     "datasets" 
## [19] "methods"   "base"     
## 
## [[5]]
##  [1] "onewaytests" "dunn.test"   "car"         "carData"     "forcats"    
##  [6] "stringr"     "dplyr"       "purrr"       "readr"       "tidyr"      
## [11] "tibble"      "ggplot2"     "tidyverse"   "knitr"       "stats"      
## [16] "graphics"    "grDevices"   "utils"       "datasets"    "methods"    
## [21] "base"       
## 
## [[6]]
##  [1] "FSA"         "onewaytests" "dunn.test"   "car"         "carData"    
##  [6] "forcats"     "stringr"     "dplyr"       "purrr"       "readr"      
## [11] "tidyr"       "tibble"      "ggplot2"     "tidyverse"   "knitr"      
## [16] "stats"       "graphics"    "grDevices"   "utils"       "datasets"   
## [21] "methods"     "base"

Data import

d1<- read.csv("/Users/koho0/Desktop/hip_fentanyl.csv")

d1 <- gather(d1,time_point,fentanyldose,fentanyl_6:fentanyl_24, factor_key=TRUE)
head(d1)
str(d1)
## 'data.frame':    231 obs. of  4 variables:
##  $ id          : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ group       : Factor w/ 3 levels "F","FO","N": 3 1 1 1 3 3 1 1 3 3 ...
##  $ time_point  : Factor w/ 3 levels "fentanyl_6","fentanyl_12",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ fentanyldose: num  219 385 219 341 211 ...
d1$time_point <-recode(d1$time_point, "'fentanyl_6'='6'")
d1$time_point <-recode(d1$time_point, "'fentanyl_12'='12'")
d1$time_point <-recode(d1$time_point, "'fentanyl_24'='24'")


d1$time_point <-factor(d1$time_point,levels=c("6","12","24"))



p=ggplot(d1,aes(d1[,3],d1[,4],color=group))
p = p + geom_boxplot(outlier.shape = NA) +geom_point(aes(color=group),position=position_dodge(width=0.75))+  ylab("Fentanyl dose(mcg)") +xlab("Time point (hours)") +
  theme_bw() + 
  theme(legend.position = c(0.1,0.9)) +
  theme(legend.title = element_blank()) 

p