now workning

This commit is contained in:
agdamsbo 2019-11-19 09:48:03 +01:00
parent a40092718b
commit 2fcf02d37e
3 changed files with 22 additions and 8 deletions

View File

@ -1,7 +1,7 @@
Package: daDoctoR Package: daDoctoR
Type: Package Type: Package
Title: FUNCTIONS FOR HEALTH RESEARCH Title: FUNCTIONS FOR HEALTH RESEARCH
Version: 0.1.0.9033 Version: 0.1.0.9034
Author: c(person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut"))) Author: c(person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut")))
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me> Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
Description: I am a Danish medical doctor involved in neuropsychiatric research. Description: I am a Danish medical doctor involved in neuropsychiatric research.

View File

@ -1,24 +1,26 @@
#' Creates Euler model from list of identifier numbers. #' Creates Euler model from list of identifier numbers.
#' #'
#' Calculates overlaps and uses eulerr package to create Euler/Venn-diagrams. Use plot() to create diagram. #' Calculates relative overlaps and uses eulerr package to create Euler/Venn-diagrams. Use plot() to create diagram.
#' Combined with an evolved calculate.overlap() from the VennDiagram library. #' Combined with an evolved calculate.overlap() from the VennDiagram library.
#' Up to five (5) dimensions. Limit set by the complexity of combinations. euler() supports more. #' Up to five (5) dimensions. Limit set by the complexity of combinations. euler() supports more.
#' @param x list of variables included. Has to be vectors of identifier numbers. #' @param x list of variables included. Has to be vectors of identifier numbers.
#' @param total data.frame, vector or integer to calculate or use as total number of participants for percentage calculation.
#' @param shape same as for euler(). These includes c("circle","ellipse"). #' @param shape same as for euler(). These includes c("circle","ellipse").
#' @keywords overlap #' @keywords overlap
#' @export #' @export
euler_plot<-function (x,shape) euler_plot<-function (x,total,shape="ellipse")
{ {
library(eulerr) library(eulerr)
sh<-shape sh<-shape
tot<-total
if (1 == length(x)) { if (1 == length(x)) {
overlap <- list("A"=x) overlap <- list("A"=x)
} }
else if (2 == length(x)) { else if (2 == length(x)) {
overlap <- list("A" = x[[1]], "B" = x[[2]], "A&B" = intersect(x[[1]], overlap <- list("A" = x[[1]], "B" = x[[2]], "A&B" = intersect(x[[1]],
x[[2]])) x[[2]]))
} }
else if (3 == length(x)) { else if (3 == length(x)) {
A <- x[[1]] A <- x[[1]]
@ -204,10 +206,20 @@ euler_plot<-function (x,shape)
"A&B&C&D&E"= a31) "A&B&C&D&E"= a31)
} }
else { else {
flog.error("Invalid size of input object", name = "VennDiagramLogger") flog.error("Invalid size of input object", name = "LazyOverlapCalculater")
stop("Invalid size of input object") stop("Invalid size of input object")
} }
eul <- euler(unlist(overlap, use.names=T),shape = sh) if (class(tot)=="vector"){
n_all<-length(tot)}
else if ((class(tot)=="integer"|class(tot)=="numeric")&length(tot)==1) {
n_all<-tot}
else if (class(tot)=="data.frame"){
n_all<-nrow(tot)
}
ov<-lapply(overlap,function(x,all=n_all,dec=1){
round(length(x)/all*100,dec)
})
eul <- euler(unlist(ov, use.names=T),shape = sh)
return(eul) return(eul)
} }

View File

@ -4,15 +4,17 @@
\alias{euler_plot} \alias{euler_plot}
\title{Creates Euler model from list of identifier numbers.} \title{Creates Euler model from list of identifier numbers.}
\usage{ \usage{
euler_plot(x, shape) euler_plot(x, total, shape = "ellipse")
} }
\arguments{ \arguments{
\item{x}{list of variables included. Has to be vectors of identifier numbers.} \item{x}{list of variables included. Has to be vectors of identifier numbers.}
\item{total}{data.frame, vector or integer to calculate or use as total number of participants for percentage calculation.}
\item{shape}{same as for euler(). These includes c("circle","ellipse").} \item{shape}{same as for euler(). These includes c("circle","ellipse").}
} }
\description{ \description{
Calculates overlaps and uses eulerr package to create Euler/Venn-diagrams. Use plot() to create diagram. Calculates relative overlaps and uses eulerr package to create Euler/Venn-diagrams. Use plot() to create diagram.
Combined with an evolved calculate.overlap() from the VennDiagram library. Combined with an evolved calculate.overlap() from the VennDiagram library.
Up to five (5) dimensions. Limit set by the complexity of combinations. euler() supports more. Up to five (5) dimensions. Limit set by the complexity of combinations. euler() supports more.
} }