All Projects → AliciaSchep → Gglabeller

AliciaSchep / Gglabeller

Licence: other
Shiny gadget for labeling points on ggplot

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Gglabeller

Ggedit
Interactively edit ggplot layer aesthetics and theme definitions
Stars: ✭ 223 (+38.51%)
Mutual labels:  shiny, ggplot2
PlotTwist
PlotTwist - a web app for plotting and annotating time-series data
Stars: ✭ 21 (-86.96%)
Mutual labels:  ggplot2, shiny
Plotly
An interactive graphing library for R
Stars: ✭ 2,096 (+1201.86%)
Mutual labels:  shiny, ggplot2
gameofthrones
🎨 Game of Thrones inspired palette for R
Stars: ✭ 69 (-57.14%)
Mutual labels:  ggplot2, plot
learning R
List of resources for learning R
Stars: ✭ 32 (-80.12%)
Mutual labels:  ggplot2, shiny
Ggthemes
Additional themes, scales, and geoms for ggplot2
Stars: ✭ 1,107 (+587.58%)
Mutual labels:  ggplot2, plot
PlotsOfData
Shiny App for comparison of samples
Stars: ✭ 47 (-70.81%)
Mutual labels:  ggplot2, shiny
ggquiver
R package for quiver plots in 'ggplot2'
Stars: ✭ 38 (-76.4%)
Mutual labels:  ggplot2, plot
parcours-r
Valise pédagogique pour la formation à R
Stars: ✭ 25 (-84.47%)
Mutual labels:  ggplot2, shiny
ggChernoff
R package for drawing Chernoff faces in ggplot2
Stars: ✭ 28 (-82.61%)
Mutual labels:  ggplot2, plot
Ggplotnim
A port of ggplot2 for Nim
Stars: ✭ 95 (-40.99%)
Mutual labels:  ggplot2, plot
Googleauthr
Google API Client Library for R. Easy authentication and help to build Google API R libraries with OAuth2. Shiny compatible.
Stars: ✭ 150 (-6.83%)
Mutual labels:  shiny
Colourpicker
🎨 A colour picker tool for Shiny and for selecting colours in plots (in R)
Stars: ✭ 144 (-10.56%)
Mutual labels:  shiny
Shinyfeedback
display user feedback next to Shiny inputs
Stars: ✭ 143 (-11.18%)
Mutual labels:  shiny
Rtutor
Creating interactive R Problem Sets. Automatic hints and solution checks. (Shiny or RStudio)
Stars: ✭ 141 (-12.42%)
Mutual labels:  shiny
Explor
Interfaces for Multivariate Analysis in R
Stars: ✭ 157 (-2.48%)
Mutual labels:  shiny
Shinyalert
🗯️ Easily create pretty popup messages (modals) in Shiny
Stars: ✭ 148 (-8.07%)
Mutual labels:  shiny
Gganimate
A Grammar of Animated Graphics
Stars: ✭ 1,744 (+983.23%)
Mutual labels:  ggplot2
Scatterd3
R scatter plot htmlwidget based on D3.js
Stars: ✭ 135 (-16.15%)
Mutual labels:  shiny
Kravis
A {K}otlin g{ra}mmar for data {vis}ualization
Stars: ✭ 134 (-16.77%)
Mutual labels:  ggplot2

gglabeller

R package with one main function, gglabeller, which launches a simple shiny gadget that enables selecting points on a ggplot to label. Label positions are determined using the fantastic ggrepel package.

Note: gglabeller has been recently updated to be compatible with ggplot2 version 3.0 – if encountering issues with previous versions of gglabeller after updating ggplot2, please try updating gglabeller to version 0.3.0 or higher! (and gglabeller 0.3.0+ now requires ggplot2 >= 3.0)

Installation

Installation via devtools:

devtools::install_github("AliciaSchep/gglabeller") 

Usage

First create a plot using ggplot2 and save it to a variable:

library(gglabeller)
library(ggplot2)
library(ggrepel)

p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + 
            theme_classic(base_size = 18)

Pass the variable to gglabeller:

gglabeller_example <- gglabeller(p, aes(label = rownames(mtcars)))

Running gglabeller will open a shiny gadget in the RStudio viewer pane (or in the browser if running R in the terminal). You can click or brush over points to select them for labelling. Clicking over an already labelled point or brushing over a set of points that have all been labelled will remove the labels.

You can also modify the ggrepel parameters via the “Parameters” tab in the app.

After clicking done, the returned object is a list storing the resulting plot and a code snippet for recreating the plot de novo.

We can make a static version of the plot to save:

gglabeller_example$plot

The code snippet can be useful if you want to incorporate the plot creation into a reproducible script:

gglabeller_example$code
#> [1] "set.seed(1502996);gglabeller_data <- p$data; gglabeller_data$gglabeller_labels <- rownames(mtcars); gglabeller_data[c(1:3, 5:7, 10:17, 19:32),'gglabeller_labels'] <- ''; p + geom_text_repel(data = gglabeller_data,mapping = aes(label = gglabeller_labels), segment.color = 'red',box.padding = unit(0.5, 'lines'))"
library(magrittr)
gglabeller_example$code %>% parse(text = .) %>% eval()

You can also just get out the indices of the labelled points:

gglabeller_example$ix
#> [1]  4  8  9 18

This can be used to get out the labels themselves.

rownames(mtcars)[gglabeller_example$ix]
#> [1] "Hornet 4 Drive" "Merc 240D"      "Merc 230"       "Fiat 128"

Text and label properties

Parameters to ggrepel, including additional text and label properties (the ... arguments to geom_text_repel or geom_label_repel), can also be passed in to gglabeller.

For example, the following will result in bold red font for the labels in the app:

gglabeller(p, aes(label = rownames(mtcars)),  fontface = "bold", color = "red")

Limitations

Requires points to label; not targetted at line plots or other non-point plots.

Relies on shiny’s nearPoints and brushedPoints functions, which require that the ‘x’ and ‘y’ aesthetics be mapped to a column name and not a transformation. For example, ggplot(mtcars, aes(x = log(wt), y = mpg)) will not work because the x aesthetic is mapped to a transformation of the column. For such a plot, one could modify the input first to create a column with the log of the value.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].