Skip to content

ggrepel text for labelling of categorical Metadata in 2D plots #68

@sreichl

Description

@sreichl

working code example with geom_text_repel()

library("ggrepel")

# plot
sc_umap_plot <- ggplot(sc_umap_data, aes(x=UMAP_1, y=UMAP_2)) +
            geom_point(aes(color=celltype), size=0.1, stroke=0, alpha=1, shape='.') + 
            # geom_text(data = sc_umap_centroids, aes(label = celltype), size = 3, color = "black", fontface = "bold") +
            geom_text_repel(data = sc_umap_centroids, aes(label = celltype), size = 3, fontface = "bold", 
                  box.padding = 0.75, max.overlaps = Inf, color = "black") +
            xlab("UMAP 1") +    
            ylab("UMAP 2") +
            theme_classic() + 
    theme(plot.title = element_text(size = 10), legend.title = element_blank(), legend.position="none",
            axis.text.x=element_blank(), axis.text.y=element_blank(),
            axis.ticks=element_blank(),
            axis.title.x=element_text(hjust=0, vjust=0),
            axis.title.y=element_text(hjust=0, vjust=0),
          axis.line=element_blank(),
          panel.border = element_rect(colour = "black", fill=NA, linewidth=0.5)
         )

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions