CHOP-CGTInformatics / ggswim

Create swimmer plots with ggplot2
https://chop-cgtinformatics.github.io/ggswim/
Other
15 stars 2 forks source link

[FEATURE] Offset Indicators for Segments #45

Open rsh52 opened 3 months ago

rsh52 commented 3 months ago

Feature Request Description

It would be nice to display markers offset from the lanes, specifically in such an example as having infusion markers as downward triangles at the points of infusion just above the lane.

Ideally we would want some way to communicate from the segment layer what the linewidth value is for the offset of the following point layer. The problem is layers are stateless and isolated from each other, and the declaration of linewidth is based on plot space whereas the actual positioning is based on pixel space as orchestrated by the grid object calculation.

Proposed Solution

There are a few avenues to pursue but each is a bit tricky.

Option 1

Add a secondary GeomPoint to a gridList() in GeomSwimLane. This would require thinking of a way to reshape how data gets fed to geom_swim_lane() and passed to the second grid object.

This is a bit undesirable because reshaping the data would likely get messy and nonstandard.

Option 2

Figure out a way to capture the linewidth grob value from GeomSwimLane via

GeomSegment$draw_panel(data, panel_params, coord,
        arrow = NULL, arrow.fill = NULL,
        lineend = "butt", linejoin = "round", na.rm = FALSE
      )$gp$lwd[[1]]

The issue here is this never gets triggered until the plot is printed. GeomSwimLane is also stateless, so values internal to this likely can't be sent outward to the next layer.

Option 3

Develop an external function that gets called after the applicable point and lane layers. This is described in a convo with ggplot2 devs on SO here : https://stackoverflow.com/questions/78330694/ggplot2-position-nudge-respective-of-linewidth

The problem here is that it's hard to control how users will layer and call these functions. It's also pretty hacky and likely to fail in a production setting.

Additional Context

Add any other context or screenshots about the feature request here.

Checklist

rsh52 commented 1 month ago

As an update, it is possible to combine Geom types and we have been successful in following similar examples to the ggplot2 text, however it has proven difficult to capture this data in the legend which is likely a non-starter for implementation.