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

Two legends when using same column for both fill and color aesthetics #304

Closed
mjwillson opened this issue May 15, 2014 · 4 comments
Closed

Comments

@mjwillson
Copy link

In [164]: data = p.DataFrame(dict(time=[0,1,2,0,1,2], lower=[1,2,3,-1,-2,-3], point=[4,5,6,-4,-5,-6], upper=[7,8,9,-7,-8,-9], type=['a','a','a','b','b','b']))

In [165]: gg.ggplot(data, gg.aes(x='time', y='point', ymin='lower', ymax='upper', fill='type', color='type')) + gg.geom_area(alpha=0.5) + gg.geom_line()
Out[165]: <ggplot: (11827541)>

Leads to a plot with two copies of the legend for type a / b. (Same happens if I leave out the geom_line)

@mjwillson mjwillson changed the title Two legends when using fill and color aesthetics Two legends when using same column for both fill and color aesthetics May 15, 2014
@mjwillson
Copy link
Author

figure_1

@has2k1
Copy link

has2k1 commented May 15, 2014

Legend drawing needs to be refactored. It should be after issues #283, #221 are done with.

@mjwillson
Copy link
Author

Note: in this specific case I managed to work around it like so:

In [43]: ga = gg.geom_area(alpha=0.5)

In [44]: ga._aes_renames = ga._aes_renames.copy()

In [45]: ga._aes_renames['color'] = u'facecolor'

In [46]: gg.ggplot(data, gg.aes(x='time', y='point', ymin='lower', ymax='upper', color='type')) + ga + gg.geom_line()
Out[46]: <ggplot: (4732741)>

@has2k1
Copy link

has2k1 commented May 16, 2014

Wow, a nice cheap hack.

arnfred added a commit to arnfred/ggplot that referenced this issue Jun 14, 2014
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 issue Jun 14, 2014
@glamp glamp closed this as completed Jun 7, 2016
has2k1 pushed a commit to has2k1/plotnine that referenced this issue Apr 25, 2017
As shown in yhat/ggpy#304 and
yhat/ggpy#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/ggpy#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.
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

No branches or pull requests

3 participants