Skip to content

Feature request: geom_mark_polygon #333

Open
@assaron

Description

@assaron

Related to: #321

I have my own algorithm to calculate the border of points group, but would like to use your label location procedure. Do you think it'd be possible to extract something like geom_mark_polygon from the current code?

This is the plot I'm interested to add labels to:

library(ggplot2)
library(ggforce)
library(data.table)

load(gzfile("border_example.rda.gz"))

ggplot(data, aes(x=UMAP_1, y=UMAP_2)) + 
    geom_point(color="grey") + 
    geom_shape(data=maskTable, aes(group=group, color=cluster),
               linewidth=1, fill=NA, expand=unit(-1, "pt")) +
    coord_fixed() + 
    theme_classic()

border_example.rda.gz

Image

Currently, the best I can do is something like this, relying on geom_mark_hull:

ggplot(data, aes(x=UMAP_1, y=UMAP_2)) +
    geom_point(color="grey") +
    geom_shape(data=maskTable, aes(group=group, color=cluster),
               linewidth=1, fill=NA, expand=unit(-1, "pt")) +
    geom_mark_hull(data=maskTable, aes(fill = NA, group=cluster, label = cluster),
                   radius=0, expand=0, con.cap=0) +
    coord_fixed() +
    theme_classic()

Image

However, I don't need to actually build a hull, since I have already have a proper polygon, and I don't want to have an additional dependency.

There are also couple of other questions:

  1. Several label connectors (for example, NK, CD8 T, and others) lead to a split point between two clusters, resulting in a bit of ambiguity. Is there a way to fix it?
  2. Is there a way to remove fill? fill=NA doesn't seem to work as I would expect.
  3. Is there a way to decrease the length of the connectors? They seem to be longer that I'd like, and I couldn't find an option to control it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions