-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Optional segment end #5154
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
Optional segment end #5154
Conversation
Am I right in understanding that this does not fully fix the dodging issue - it only help for fully vertical or fully horizontal segments? |
Indeed, it only helps with horizontal or vertical segments. I'm not sure what dodging with other angles should do, but that isn't addressed by this PR. |
intuitively dodging a segment would use the width/height of it's bounding box |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - as discussed we will tackle dodging fully in another PR (or multiple)
Merge branch 'main' into segment_optional_end # Conflicts: # man/geom_segment.Rd
Thanks for the review Thomas! I'm merging this despite a failing test on devel (explained here: #5296 (comment)) |
Hi I had a question regarding the automatic flipping running in current ggplot2 we get the below library(patchwork)
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.2.3
set.seed(42)
df <- data.frame(
x = rep(letters[1:3], each = 2),
y = rpois(6, 10),
group = rep(LETTERS[1:2], 3)
)
a<- ggplot(df ,aes(x=x,y=y, colour = group))+
geom_point(size=5,alpha=0.5,
position = position_dodge(width = 0.9))+
geom_segment(aes(yend=0,xend=x),
position = position_dodge(width = 0.9))
b<- ggplot(df ,aes(x=y,y=x, colour = group))+
geom_point(size=5,alpha=0.5,
position = position_dodge(width = 0.9))+
geom_segment(aes(xend=0,yend=x),
position = position_dodge(width = 0.9))
a | b Created on 2023-05-10 with reprex v2.0.2 |
Yes you'd still need to specify devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
library(patchwork)
set.seed(42)
df <- data.frame(
x = rep(letters[1:3], each = 2),
y = rpois(6, 10),
group = rep(LETTERS[1:2], 3)
)
a<- ggplot(df ,aes(x=x,y=y, colour = group))+
geom_point(size=5,alpha=0.5,
position = position_dodge(width = 0.9))+
geom_segment(aes(yend=0), # Note, 'xend' is missing
position = position_dodge(width = 0.9))
b<- ggplot(df ,aes(x=y,y=x, colour = group))+
geom_point(size=5,alpha=0.5,
position = position_dodge(width = 0.9))+
geom_segment(aes(xend=0), # Note, 'yend' is missing
position = position_dodge(width = 0.9))
a | b Created on 2023-05-10 with reprex v2.0.2 |
thank you I will figure out how to switch |
Was this broken at some point? The examples at the top no longer work in 3.4.4 (haven't tried 3.5.0 yet), |
I don't think it was ever broken, but these examples should only work from 3.5.0 onwards |
Gotcha, sorry for the noise. The date it was merged made me think it was incorporated earlier, sorry! |
This PR aims to fix #5140, fix #3627 and fix #3617.
Briefly, it makes one of
xend
/yend
optional ingeom_segment()
. The missing aesthetic gets filled byx
andy
respectively.Visual demo:
Created on 2023-01-21 with reprex v2.0.2