Skip to content

Commit 2a57082

Browse files
added pretty plots
1 parent 7e6f3a5 commit 2a57082

7 files changed

Lines changed: 110 additions & 24 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Imports:
3838
Suggests:
3939
corrplot,
4040
ggpedigree,
41+
ggplot2,
4142
discord,
4243
dplyr,
4344
EasyMx,

NEWS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# BGmisc 1.4.1
2-
## In progress
32
* replaced print with message in all functions
43
* Exposed several internal functions to the user
54
* refactored addPhantomParents to be more efficient

R/estimateCIs.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ calculateCIs <- function(tbl,
124124
#'
125125
#' These functions convert correlation coefficients (r) to Fisher's z-scores and back.
126126
#' @param rho A numeric vector of correlation coefficients.
127-
#' @param z A numeric vector of Fisher's z-scores.
128127
#' @return A numeric vector of transformed values.
129128
#' @keywords internal
130129
#' @details
@@ -134,6 +133,12 @@ calculateCIs <- function(tbl,
134133
0.5 * log((1 + rho) / (1 - rho))
135134
} # converts r to z
136135

136+
137+
#' @inherit .fisherz title
138+
#' @inherit .fisherz return
139+
#' @param z A numeric vector of Fisher's z-scores.
140+
#' @keywords internal
141+
#'
137142
.fisherz2r <- function(z) {
138143
(exp(2 * z) - 1) / (1 + exp(2 * z))
139144
} # converts back again

man/dot-fisherz.Rd

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dot-fisherz2r.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/v2_pedigree.Rmd

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To illustrate this functionality, let us generate a pedigree. This pedigree has
2727
```{r}
2828
## Loading Required Libraries
2929
library(BGmisc)
30-
30+
library(ggpedigree)
3131
set.seed(5)
3232
df_ped <- simulatePedigree(
3333
kpc = 4,
@@ -53,7 +53,7 @@ summarizeFamilies(df_ped, famID = "fam")$family_summary
5353
```
5454
## Plotting Pedigree
5555

56-
Pedigrees are visual diagrams that represent family relationships across generations. They are commonly used in genetics to trace the inheritance of specific traits or conditions. This vignette will guide you through visualizing simulated pedigrees using the `plotPedigree` function. This function is a wrapper function for `Kinship2`'s base R plotting.
56+
Pedigrees are visual diagrams that represent family relationships across generations. They are commonly used in genetics to trace the inheritance of specific traits or conditions. This vignette will guide you through visualizing simulated pedigrees using the `plotPedigree` function. This function is a wrapper function for `Kinship2`'s base R plotting. The sister package ggpedigree has a much nicer plotting function. It's also available on CRAN, but it is not a dependency of BGmisc. If you want to use ggpedigree, you can install it with `install.packages("ggpedigree")` and then use `ggplot2` syntax to plot pedigrees.
5757

5858
### Single Pedigree Visualization
5959

@@ -64,6 +64,18 @@ To visualize a single simulated pedigree, use the `plotPedigree()` function.
6464
plotPedigree(df_ped)
6565
```
6666

67+
The nicer implementation of the `plotPedigree` function allows you to visualize the pedigree structure, including family relationships and individual characteristics. The plot displays individuals across generations, with lines connecting parents to their children, and spouses connected by horizontal lines.
68+
69+
```{r, warning=FALSE, message=FALSE,fig.width=8, fig.height=6}
70+
library(ggpedigree)
71+
72+
df_ped_recoded <- recodeSex(df_ped, code_male = "M", recode_male=1, recode_female = 0)
73+
74+
ggpedigree::ggpedigree(df_ped_recoded,
75+
personID = "ID",
76+
code_male = 1)
77+
78+
```
6779

6880
In the resulting plot, biological males are represented by squares, while biological females are represented by circles, following the standard pedigree conventions.
6981

@@ -88,8 +100,37 @@ plotPedigree(df_ped_3, width = 3)
88100
89101
# Plot the 4-generation pedigree
90102
plotPedigree(df_ped_4, width = 1)
103+
91104
```
92105

106+
Alternatively, you can use the `ggpedigree` package to plot multiple pedigrees side by side. This package allows for more customization and better aesthetics in pedigree visualization.
107+
108+
```{r, echo=FALSE,fig.width=8, fig.height=6}
109+
library(ggplot2)
110+
111+
df_ped_3$famID <- 1
112+
df_ped_3$fam <-NULL
113+
df_ped_3$ID <- df_ped_3$ID/100
114+
df_ped_3$dadID <- df_ped_3$dadID/100
115+
df_ped_3$momID <- df_ped_3$momID/100
116+
df_ped_3$spID <- df_ped_3$spID/100
117+
df_ped_4$famID <- 2
118+
df_ped_4$fam <-NULL
119+
120+
df_ped_all <- rbind(df_ped_3, df_ped_4)
121+
df_ped_all <- recodeSex(df_ped_all, code_male = "M",
122+
recode_male=1,
123+
recode_female = 0)
124+
125+
ggpedigree::ggpedigree(df_ped_all,
126+
personID = "ID",
127+
famID = "famID",
128+
config = list(label_method = "geom_text",
129+
label_text_size =1),
130+
code_male = 1) +
131+
facet_wrap(~famID, scales = "free")
132+
```
133+
93134
By examining the side-by-side plots, you can contrast and analyze the structures of different families, tracing the inheritance of specific traits or conditions if needed.
94135

95136

0 commit comments

Comments
 (0)