-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Summary
Extend ggPedigree to offer genogram functionality—supporting non‑genetic relationships (adoption, guardianship), partnership states (married, separated, cohabiting, divorced, consanguineous), multiple‑birth connectors, pregnancy and stillbirth symbols, deceased indicators, and region shading for shared traits—via new geoms, aesthetics, and helper utilities that integrate seamlessly with the existing compute → connect → draw pipeline.
Motivation
Clinical, social‑work, and behavioral‑science users rely on genograms to capture blended families, social ties, and phenotypic annotations that go beyond classical Mendelian pedigrees. At present, they must layer ad‑hoc geom_segment or annotate() calls on top of ggPedigree, producing brittle code and inconsistent symbolism.
Adding native genogram support will
-
eliminate boilerplate and manual annotation hacks,
-
standardize visual conventions across studies and clinics,
-
enable programmatic mapping of relational data to graphics (improving reproducibility), and
-
broaden ggPedigree's user base to genetic counsellors, clinicians, psychologists, and social workers.
Implementation
1 Data model extensions
# new optional columns expected by ggPedigree
relationship_type # factor: married, divorced, separated, cohabiting,
# adoption, guardianship, consanguineous
twin_group # integer: shared ID for twins/triplets/etc.
status # factor: alive, deceased, stillbirth, pregnancy
shading_group # factor/chr: id of region‑fill grouping for shared traits
Provide as_genogram_df() to coerce tidygraph/kinship objects or legacy pedigree tables into this schema.
Let ped2fam() call the new helper when any of these columns are detected.
2. Config additions (all default‑off)
config <- list(
segment_adoption_linetype = "33", # dashed
segment_guardian_color = "blue",
segment_divorced_linetype = "11",
segment_consanguineous_loop_lty = "solid",
status_deceased_shape = 4, # X‑through‑square/circle
status_stillbirth_shape = 17, # triangle
status_pregnancy_shape = 23, # diamond
twin_connector_width = .08, # relative x‑offset
shading_alpha = .2,
relationship_palette = c(
married = "black", divorced = "black", separated = "black",
cohabiting = "black", adoption = "darkgreen",
guardianship = "blue", consanguineous = "red"
)
)
3. Compute phase
Sex & status recode – extend recodeSex() (or wrap) to recode status, returning sex and status factors used downstream.
Coordinate generation – in calculateCoordinates():
When twin_group present, assign identical y_pos to group members and offset their x_pos by ±twin_connector_width.
Store midpoint coordinates (x_mid_multibirth, y_mid_multibirth) for the A‑frame twin connector.
4. Connection phase (calculateConnections())
Return a single tibble with columns:
x_pos, y_pos, xend, yend, rel_class, linetype, color,
loop_radius, arrow, curvature
Rules:
Partnership lines: rel_class determined by relationship_type; set linetype/color via relationship_palette.
Adoption/guardianship: dashed or coloured lines between parent and child, flagged so legend keys render correctly.
Consanguineous marriages: draw loop from one spouse up and over to the other; supply loop_radius.
Twin connectors: vertical drop from parent‑midpoint to y_mid_multibirth, then short up‑angled segments to each twin’s x_pos.
5. Rendering phase
New geoms
geom_relationship() – internal helper used by ggPedigree.core() to draw partnership lines, adoption connectors, consanguineous loops (curved segments).
geom_twin_connector() – draws the A‑frame under multiple births.
geom_genogram() – convenience wrapper that calls ggPedigree() with genogram defaults active.
Points
Map shape = status and optionally fill = shading_group.
When shading_group present, overlay semi‑transparent geom_polygon spanning bounding boxes of all nodes in the group (region shading).
Scales & guides
scale_linetype_genogram(), scale_color_relationship() keyed on rel_class.
scale_shape_status() keyed on status.
guide_genogram() builds composite legend keys (e.g., dashed adoption line between square and circle).
6. Backward compatibility
All new features are opt‑in: if the extra columns are absent and geom_genogram() is not called, existing pedigrees render exactly as before.
New config entries default to inactive values, so current workflows need no changes.