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

Legend rework #327

Merged
merged 3 commits into from
Jun 26, 2014
Merged

Legend rework #327

merged 3 commits into from
Jun 26, 2014

Conversation

arnfred
Copy link

@arnfred arnfred commented Jun 14, 2014

Rework of legend

As shown in #304 and #89 the current legend is drawn once per aesthetic (outside of x and y). This behaviour creates duplicate information when we use for example color and fill along the
same variable.

I've reworked the legend to group information per variable and display for example one line showing both shape, color and alpha information. The reworked legend also address: #273.

New Features

  • Group legend information per variable
  • Implement alpha
  • Better position legend (The vertical position was centered according to the top of the frame before)
  • Fixed issue with legend overlapping
  • Fixed problem with legend inventing numeric values. For numeric columns with less than 5 unique values, the current legend would interpolate them to write 5 continuous values

Things that don't work

  • No custom rearrangement (say, making swapping line 1 and 2 in the legend)
  • Legend might be longer than plot. Currently it breaks in to two columns, but if the plot is drawn smaller then I can't see a way to adjust the legend to this behaviour

Changes

  • I've personally had the problem that the legend would interpolate between numeric values even when there were less than 5 unique values in the data. I've changed this behaviour so the legend puts a label for every value when there are less than 8. Currently the color scheme in this case is discrete, but I'm not convinced this is the best solution. I generally think distinguishing between discrete and continuous data types makes sense, but for some continuous cases we might want to use the set of values that are present in the data instead of interpolating. I'm unsure whether the way I've changed this is the right way to do it, so I welcome comments on this matter.
  • For the labels to be consistent across groups I had to make sure they were calculated in one place instead of across different files (components/colors.py, components/alphas.py, components/sizes.py etc) as it's currently done. To do so I've added a function called get_labels to components/legend.py and call it from the respective files. I think this counts as a work around and potentially a refactoring of the codebase would eliminate the need for a get_labels function, but currently I don't see any other obvious way of doing it.

Examples

legend_alpha
legend_alpha_rect
legend_linetype

Fixed issues:
- The AnchoredOffsetbox was originally set to at add loc=6 which
  vertically centers the legend in the plot, creating legends that were
  too high or too low compared to the upper plot edge.
- legends with many items would often overlap due to the spacing between
  separate legends being constant
As shown in yhat#304 and
yhat#89 the current legend is drawn
once per aesthetic (outside of x and y). This behaviour creates
duplicate information when we use for example color and fill along the
same variable.

I've reworked the legend to group information per variable and display
for example one line showing both shape, color and alpha information.

The reworked legend also address: yhat#273.

New Features
- Group legend information per variable
- Implement alpha
- Better position legend (The vertical position was centered according
  to the top of the frame before)
- Fixed issue with legend overlapping
- Fixed problem with legend inventing numeric values. For numeric
  columns with less than 5 unique values, the current legend would
  interpolate them to write 5 continuous values

Things that doesn't work:
- No custom rearrangement (say, making swapping line 1 and 2 in the
  legend)
- Legend might be longer than plot. Currently it breaks in to two
  columns, but if the plot is drawn smaller then I can't see a way to
  adjust the legend to this behaviour

Changes:
- I've personally had the problem that the legend would interpolate
  between numeric values even when there were less than 5 unique values
  in the data. I've changed this behaviour so the legend puts a label
  for every value when there are less than 8. Currently the color scheme
  in this case is discrete, but I'm not convinced this is the best
  solution. I generally think distinguishing between discrete and
  continuous data types makes sense, but for some continuous cases we
  might want to use the set of values that are present in the data
  instead of interpolating. I'm unsure whether the way I've changed this
  is the right way to do it, so I welcome comments on this matter.
@arnfred arnfred mentioned this pull request Jun 14, 2014
@has2k1
Copy link

has2k1 commented Jun 14, 2014

#283 (and whatever implications there after) not withstanding, the legends are now smarter and cleaner.

In ggplot2, every geom draws its own legend or assigns another geom to the task, so you have stuff like geom_boxplot doing something interesting.

For the failing tests, I think you may have been bitten by the python 3 generator return stuff.

@glamp
Copy link
Contributor

glamp commented Jun 26, 2014

you are a savior. this looks great!

glamp added a commit that referenced this pull request Jun 26, 2014
@glamp glamp merged commit 7945b77 into yhat:master Jun 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants