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
geom_vline messes up geom_line legend, if show_guide = TRUE #1267
Comments
updated, because earlier version was too complicated. |
Here's an even simpler example: df <- data.frame(x = c(1, 2), y = c(1, 2), z = c("a", "b"))
threshold <- data.frame(x = c(1.2, 1.5), name = c("bar", "foo"))
ggplot(df, aes(x, y, colour = z)) +
geom_point() +
geom_vline(aes(xintercept = x, linetype = name), show.legend = TRUE, data = threshold) |
There are a couple of problems here. There's a bug in the legend generation code which means that the legends where inheriting aesthetics when they shouldn't. There's another problem that Both these cases now work: df <- data.frame(x = c(1, 2), y = c(1, 2), z = c("a", "b"))
ggplot(df, aes(x, y, colour = z)) +
geom_point() +
geom_vline(xintercept = 1.5))
threshold <- data.frame(x = c(1.2, 1.5), name = c("bar", "foo"))
ggplot(df, aes(x, y, colour = z)) +
geom_point() +
geom_vline(aes(xintercept = x, linetype = name), data = threshold) |
Hello, Unfortunately a problem persists in the legends of the lines if you also have to add a horizontal line: Do you have a suggestion how to have just a vertical line, or horizontal line and not a cross in the legends? Many thanks |
Is there any solution to the cross problem demonstrated by @rdcomineor when using both geom_hline and geom_vline? |
@cyberang3l, I couldn't run the example given by @rdcomineor, but I had a similar problem with The mapping to color still works and this produces a legend for the |
The problem still persists if you have hline and vline in the same chart. |
@fmassicano, as this issue is closed, why don't you post a new issue with a working, minimal example. Also, please post screenshot with the reprex package. |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Let's say I have some line graph via
geom_line
and would like to add somegeom_vline
s as thresholds.Let's further say that I have several such
geom_vline
s and would therefore require a legend.Here's the base layer plot:
So far, so good:
Now let's try and add the threshold via
geom_hline
with a custom legend:Not so great, the base-layer legends are all screwed up:
Ok, let's see whether we can make this work via
geom_linerange()
with separate dataframes:Works ok, except that the
geom_linerange
doesn't fill the entire y-height of the plot, but ok:Then wouldn't we expect the same approach to work via
geom_vline()
with a separate dataframe?Nope, the same problem with screwed up legends returns:
Bug or my mistake?
May be related:
The text was updated successfully, but these errors were encountered: