The ggPedigreeInteractive()
function extends the static
pedigree plots generated by ggPedigree()
into fully
interactive Plotly
widgets. This allows users to explore
pedigree data in a more dynamic way, with features such as hover text,
zooming, and panning. This vignette walks through: - Basic usage of
ggPedigreeInteractive()
- Customizing the interactive plot
- Adding tooltips for additional information
# Load required packages
library(BGmisc) # ships the sample 'potter' pedigree
library(ggplot2) # used internally by ggPedigree*
library(viridis) # viridis for color palettes
library(plotly) # conversion layer for interactivity
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
library(ggpedigree) # the package itself
The package includes a small toy pedigree for the Harry Potter universe:
# Load the example data
data("potter")
# Display the first few rows of the dataset
head(potter)
#> personID famID name gen momID dadID spouseID sex twinID zygosity
#> 1 1 1 Vernon Dursley 1 101 102 3 1 NA <NA>
#> 2 2 1 Marjorie Dursley 1 101 102 NA 0 NA <NA>
#> 3 3 1 Petunia Evans 1 103 104 1 0 NA <NA>
#> 4 4 1 Lily Evans 1 103 104 5 0 NA <NA>
#> 5 5 1 James Potter 1 NA NA 4 1 NA <NA>
#> 6 6 1 Dudley Dursley 2 3 1 NA 1 NA <NA>
A minimal call is just:
…but you will usually want to identify the core primary‑key columns in advance:
plt <- ggPedigreeInteractive(
potter,
famID = "famID",
personID = "personID",
momID = "momID",
dadID = "dadID"
) |> plotly::hide_legend()
The above code generates an interactive pedigree plot of the Potter
family tree. You can zoom in, pan around, and hover over nodes to see
more information. You can do much more with the
ggPedigreeInteractive()
function, including customizing
labels, colors, and tooltips. To experience the full list of options,
refer to the online article.