new function including sample data

This commit is contained in:
AG Damsbo 2022-11-25 14:30:57 +01:00
parent f0da458218
commit aaf08d824f
10 changed files with 216 additions and 4 deletions

View File

@ -1,6 +1,6 @@
Package: stRoke
Title: Tools for work in clinical stroke research
Version: 0.22.10.1
Version: 0.22.11.1
Authors@R:
person("Andreas Gammelgaard", "Damsbo", , "agdamsbo@clin.au.dk", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7559-1154"))
@ -18,8 +18,12 @@ Suggests:
Language: en-US
Config/testthat/edition: 3
Imports:
dplyr,
ggplot2,
gtsummary,
MASS,
rankinPlot,
stats
stats,
tidyr
Depends:
R (>= 2.10)

View File

@ -6,12 +6,17 @@ export(cpr_check)
export(cpr_dob)
export(cpr_female)
export(generic_stroke)
export(index_plot)
export(plot_olr)
export(quantile_cut)
export(source_lines)
import(ggplot2)
import(stats)
import(tidyr)
importFrom(MASS,polr)
importFrom(dplyr,filter)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(gtsummary,add_overall)
importFrom(gtsummary,tbl_summary)
importFrom(rankinPlot,grottaBar)

74
R/index_plot.R Normal file
View File

@ -0,0 +1,74 @@
utils::globalVariables(c("name","value","facet"))
#' Plot multidimensional cognitive test scores
#'
#' Plot index scores from five dimensional cognitive testing. Includes option to facet.
#'
#' @param ds complete data frame
#' @param id colname of id column. Base for colouring
#' @param sub_plot main outcome scores variable to plot
#' @param scores variables to subset for plotting. Has to follow standard naming (is to be changed)
#' @param dom_names domain names for axis naming
#' @param facet.by variable to base facet_grid on
#'
#' @return ggplot element
#'
#' @import ggplot2 tidyr
#' @importFrom dplyr mutate
#' @importFrom dplyr select
#' @importFrom dplyr filter
#'
#' @export
#'
#' @examples
#' data(score)
#' index_plot(score |> dplyr::filter(event=="A"))
index_plot <- function(ds,id="id",sub_plot="_is",scores=c("_is","_lo","_up","_per"),dom_names=c("immediate","visuospatial","verbal","attention","delayed","total"),facet.by=NULL){
df_plot<-ds|>
dplyr::select(c(id,
facet.by,
ends_with(scores)))|>
tidyr::pivot_longer(cols=-c(id,facet.by))|>
subset(grepl(sub_plot,name))|>
dplyr::mutate(value=as.numeric(value),
name=factor(name,labels = dom_names))
if (!is.null(facet.by)){
colnames(df_plot)<-c("id","facet","name","value")
} else {
colnames(df_plot)<-c("id","name","value")
}
if (sub_plot=="_is"){
index_plot<-df_plot|>
ggplot2::ggplot(mapping = ggplot2::aes(x=name, y=value, color=factor(id), group=factor(id))) +
ggplot2::geom_point() +
ggplot2::geom_path() +
ggplot2::expand_limits(y=c(40,160)) +
ggplot2::scale_y_continuous(breaks=seq(40,160,by=10)) +
ggplot2::ylab("Index Score") +
ggplot2::xlab("Domain")+
ggplot2::labs(colour = "ID")
}
if (sub_plot=="_per"){
index_plot<-df_plot|>
ggplot2::ggplot(mapping = ggplot2::aes(x=name, y=value, fill=factor(id)))+
ggplot2::geom_col(position = "dodge") +
ggplot2::expand_limits(y=c(0,100)) +
ggplot2::scale_y_continuous(breaks=seq(0,100,by=10)) +
ggplot2::xlab("Cognitive domains") +
ggplot2::ylab("Percentile") +
ggplot2::labs(fill = "ID")
}
if (!is.null(facet.by)){
index_plot + facet_grid(cols=vars(facet)) +
ggplot2::theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
} else {
index_plot
}
}

36
R/score.R Normal file
View File

@ -0,0 +1,36 @@
#' Data frame with sample data of cognitive testing score
#'
#' Contains non-identifiable organic trial data from a five-dimensional cognitive test.
#'
#' @format A data frame with 20 rows and 26 variables:
#' \describe{
#' \item{id}{id}
#' \item{event}{event}
#' \item{a_is}{domain a index score}
#' \item{b_is}{domain b index score}
#' \item{c_is}{domain c index score}
#' \item{d_is}{domain d index score}
#' \item{e_is}{domain e index score}
#' \item{i_is}{total index score}
#' \item{a_lo}{domain a lower ci}
#' \item{b_lo}{domain b lower ci}
#' \item{c_lo}{domain c lower ci}
#' \item{d_lo}{domain d lower ci}
#' \item{e_lo}{domain e lower ci}
#' \item{i_lo}{total lower ci}
#' \item{a_up}{domain a upper ci}
#' \item{b_up}{domain b upper ci}
#' \item{c_up}{domain c upper ci}
#' \item{d_up}{domain d upper ci}
#' \item{e_up}{domain e upper ci}
#' \item{i_up}{total upper ci}
#' \item{a_per}{domain a percentile}
#' \item{b_per}{domain b percentile}
#' \item{c_per}{domain c percentile}
#' \item{d_per}{domain d percentile}
#' \item{e_per}{domain e percentile}
#' \item{i_per}{total percentile}
#' }
#' @usage data(score)
"score"

View File

@ -2,7 +2,7 @@
#'
#' Contains of non-identifiable data from the [TALOS trial](https://doi.org/10.1161/STROKEAHA.117.020067/)
#'
#' @format A data frame with 200 rows and 1 variable:
#' @format A data frame with 200 rows and 6 variables:
#' \describe{
#' \item{rtreat}{Randomisation}
#' \item{mrs_1}{Modified Rankin scale score at follow-up}

BIN
data/score.rda Normal file

Binary file not shown.

View File

@ -7,22 +7,33 @@ ORCID
Randomisation
TALOS
Vectorised
af
agdamsbo
christophergandrud
ci
colname
colouring
cpr
cprs
daDoctoR
ddmmyy
ddmmyyxxxx
df
dk
eb
eg
forrestplot
gg
ggplot
github
grotta
grottaBar
helpfull
https
mRS
olr
polr
sst
www
xxxx
yyyy

38
man/index_plot.Rd Normal file
View File

@ -0,0 +1,38 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/index_plot.R
\name{index_plot}
\alias{index_plot}
\title{Plot multidimensional cognitive test scores}
\usage{
index_plot(
ds,
id = "id",
sub_plot = "_is",
scores = c("_is", "_lo", "_up", "_per"),
dom_names = c("immediate", "visuospatial", "verbal", "attention", "delayed", "total"),
facet.by = NULL
)
}
\arguments{
\item{ds}{complete data frame}
\item{id}{colname of id column. Base for colouring}
\item{sub_plot}{main outcome scores variable to plot}
\item{scores}{variables to subset for plotting. Has to follow standard naming (is to be changed)}
\item{dom_names}{domain names for axis naming}
\item{facet.by}{variable to base facet_grid on}
}
\value{
ggplot element
}
\description{
Plot index scores from five dimensional cognitive testing. Includes option to facet.
}
\examples{
data(score)
index_plot(score |> dplyr::filter(event=="A"))
}

44
man/score.Rd Normal file
View File

@ -0,0 +1,44 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/score.R
\docType{data}
\name{score}
\alias{score}
\title{Data frame with sample data of cognitive testing score}
\format{
A data frame with 20 rows and 26 variables:
\describe{
\item{id}{id}
\item{event}{event}
\item{a_is}{domain a index score}
\item{b_is}{domain b index score}
\item{c_is}{domain c index score}
\item{d_is}{domain d index score}
\item{e_is}{domain e index score}
\item{i_is}{total index score}
\item{a_lo}{domain a lower ci}
\item{b_lo}{domain b lower ci}
\item{c_lo}{domain c lower ci}
\item{d_lo}{domain d lower ci}
\item{e_lo}{domain e lower ci}
\item{i_lo}{total lower ci}
\item{a_up}{domain a upper ci}
\item{b_up}{domain b upper ci}
\item{c_up}{domain c upper ci}
\item{d_up}{domain d upper ci}
\item{e_up}{domain e upper ci}
\item{i_up}{total upper ci}
\item{a_per}{domain a percentile}
\item{b_per}{domain b percentile}
\item{c_per}{domain c percentile}
\item{d_per}{domain d percentile}
\item{e_per}{domain e percentile}
\item{i_per}{total percentile}
}
}
\usage{
data(score)
}
\description{
Contains non-identifiable organic trial data from a five-dimensional cognitive test.
}
\keyword{datasets}

View File

@ -5,7 +5,7 @@
\alias{talos}
\title{Data frame with sample of TALOS data}
\format{
A data frame with 200 rows and 1 variable:
A data frame with 200 rows and 6 variables:
\describe{
\item{rtreat}{Randomisation}
\item{mrs_1}{Modified Rankin scale score at follow-up}