Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of empty strings #51

Closed
aphalo opened this issue Sep 9, 2016 · 5 comments
Closed

Handling of empty strings #51

aphalo opened this issue Sep 9, 2016 · 5 comments
Labels

Comments

@aphalo
Copy link

@aphalo aphalo commented Sep 9, 2016

I think it would be best to handle "" as a special case, not drawing segments and empty boxes in this case. It would also help in cases when one wants not to label some observations but still have the observations themselves, e.g., points on the plot, as objects to repel from.

text_repel
label_repel

@slowkow
Copy link
Owner

@slowkow slowkow commented Sep 12, 2016

Thank you for describing the issue and providing images! I like your suggestion!

This merits a detailed example in the documentation to make sure users know how to use this feature.

If we go ahead with this suggestion, then we'll have 3 possibilities for what happens to a data point:

  1. The data point has a non-empty string, so it is labeled with a pointer and text.

  2. The data point has an empty string, so it is unlabeled, but it also repels other labels. This addresses issue #49.

  3. The data point has NA as the string, so it is unlabeled and does not repel other labels. Effectively, it is the same as excluding the data point entirely. Also, R reports a warning about missing values (as it does for geom_text, for example).

    Warning message:
    Removed 1 row containing missing values (geom_text_repel). 
    
@slowkow slowkow added the enhancement label Sep 12, 2016
@aphalo
Copy link
Author

@aphalo aphalo commented Sep 13, 2016

To complement this my new stat can reset the labels to "" based on the density of observations. This would take care of the "static" case, not the "reactive" one, which would need to be handled by text_repel and label_repel on the fly. The images above were produced using the following code:

ggplot(data = d, aes(x, y, label = lab, color = group)) +
geom_point() +
stat_dens2d_labels(geom = "text_repel", 
                              keep.fraction = 0.25,
                              label.fill = "")

and

ggplot(data = d, aes(x, y, label = lab, color = group)) +
geom_point() +
stat_dens2d_labels(geom = "label_repel", 
                             keep.fraction = 0.25,
                             label.fill = "")

In the current version label.fill defaults to NA but I will make "" the default as if the repel geoms are changed as suggested, "" will become the most useful value.

slowkow added a commit that referenced this issue Oct 3, 2016
fixes issue #51

when a label is the empty string "":

- do not draw a text label for it
- repel other text labels from the data point labeled by the empty string
@slowkow
Copy link
Owner

@slowkow slowkow commented Oct 3, 2016

@aphalo Could I ask you to try 0.6.0? Does this work the way you expect with empty strings?

devtools::install_github("slowkow/ggrepel@0.6.0")
@aphalo
Copy link
Author

@aphalo aphalo commented Oct 4, 2016

@slowkow Yes, indeed! Works nicely. Please find attached my examples above rerun with "slowkow/ggrepel@0.6.0".
pos-unnamed-chunk-68-1
pos-unnamed-chunk-69-1
I also tried larger values for keep.fraction and the plots are fine as long as crowding is not so much as to make satisfactory repositioning impossible.
Many thanks!

@slowkow
Copy link
Owner

@slowkow slowkow commented Oct 4, 2016

Excellent, and thank you very much for sharing the figures. I'm going to add an example like this to the documentation soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.