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 legend bugs #857

Closed
tdhock opened this issue Sep 12, 2013 · 3 comments
Closed

Two legend bugs #857

tdhock opened this issue Sep 12, 2013 · 3 comments

Comments

@tdhock
Copy link
Contributor

tdhock commented Sep 12, 2013

## BUG 1: the fill legend should use shape=21 so that I can see color
## differences in the legend and decode the fill aesthetic.
df <- data.frame(x=1:3,y=1:3,
                 fill=c("B","R","R"),
                 shape=c("circle","circle","cross"))
p <- ggplot(df)+
  geom_point(aes(x, y, fill=fill, shape=shape))+
  scale_shape_manual(values=c(circle=21,cross=13))+
  scale_fill_manual(values=c(B="blue",R="red"))
print(p)

## BUG 2: previous problem, plus too many items in the shape legend.
df <- data.frame(x=1:3,y=1:3,fill=factor(c(1,2,2)),shape=c(21,21,13))
p <- ggplot(df)+
  geom_point(aes(x, y, fill=fill, shape=shape))+
  scale_shape_identity(guide="legend")+
  scale_fill_identity(guide="legend")
print(p)
@BrianDiggs
Copy link
Contributor

Here are workarounds for these two issues (I'm not saying they aren't bugs, just that there exists a way to get what you want):

ggplot(df)+
  geom_point(aes(x, y, fill=fill, shape=shape))+
  scale_shape_manual(values=c(circle=21,cross=13))+
  scale_fill_manual(values=c(B="blue",R="red"), 
                    guide=guide_legend(override.aes=aes(shape=21)))

and

ggplot(df)+
  geom_point(aes(x, y, fill=fill, shape=shape))+
  scale_shape_identity(guide="legend", breaks=c(13,21))+
  scale_fill_identity(guide="legend")

(bearing in mind that df is different for the two examples).

@hadley
Copy link
Member

hadley commented Feb 24, 2014

This sounds like a great feature/horrible bug, but unfortunately we don't currently have the development bandwidth to support it/fix it. If you'd like to submit a pull request that implements this feature/fixes this bug, please follow the instructions in the development vignette.

@hadley hadley closed this as completed Feb 24, 2014
@devu123
Copy link

devu123 commented Jun 10, 2016

+1 for fixing this in newer versions, or direction for a pull request;
I would like to help with a generalized solution for a graph with an unknown number of shapes/groups,
with unknown names before plotting.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants