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

position_dogev for points #5809

Closed
smouksassi opened this issue Mar 26, 2024 · 2 comments · Fixed by #5845
Closed

position_dogev for points #5809

smouksassi opened this issue Mar 26, 2024 · 2 comments · Fixed by #5845
Labels
feature a feature request or enhancement positions 🥇

Comments

@smouksassi
Copy link

ggstance has been deprecated and recently was removed from CRAN @lionel- kindly offered that he will make a last ditch edits to re instate it on CRAN but it is bound to disappear.

One of the last things that we still cannot do in ggplot2 is being able to dodge point vertically for various reasons:
the geom_point has no orientation that can force the position to work in the alternative direction

is there a way to enable vertical dodging for points ? or to force geom_point to have flipped aes ?
https://github.com/tidyverse/ggplot2/blob/main/R/position-dodge.R#L97

library(ggplot2)
library(ggstance)
#> 
#> Attaching package: 'ggstance'
#> The following objects are masked from 'package:ggplot2':
#> 
#>     geom_errorbarh, GeomErrorbarh
library(patchwork)
df <- data.frame(
  trt = c(1,1,2,2),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, 5.3, 3.3, 4.2),
  lower = c(0.8, 4.6, 2.4, 3.6)
)

 
 ggplot(df, aes( resp,trt, colour = group))+
   geom_linerange(aes(xmin = lower, xmax = upper),
                   position = position_dodge(width=0.2),orientation ="y")+
   geom_point(aes(group=interaction(group,trt)),position = position_dodge(width=0.2)) |
 ggplot(df, aes( resp,trt, colour = group))+
   geom_linerange(aes(xmin = lower, xmax = upper),
                  position = position_dodge(width=0.2),orientation ="y")+
   geom_point(aes(group=interaction(group,trt)),position = position_dodgev(height=0.2))

Created on 2024-03-26 with reprex v2.1.0

@karawoo
Copy link
Member

karawoo commented Mar 26, 2024

Does geom_pointrange() work? Or do you have a more complex use case that requires a separate point geom?

library(ggplot2)

df <- data.frame(
  trt = c(1,1,2,2),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, 5.3, 3.3, 4.2),
  lower = c(0.8, 4.6, 2.4, 3.6)
)

ggplot(df, aes( resp,trt, colour = group))+
  geom_pointrange(
    aes(xmin = lower, xmax = upper),
    position = position_dodge(width = 0.2),
    orientation ="y"
  ) 

Created on 2024-03-26 with reprex v2.1.0

@smouksassi
Copy link
Author

Hi yes indeed my use case is more complex where I build a plot layer by layer and where user can add a point that should match the positon of a linerange. I tried to provide a minimum reprex above.
also applies to geom text

library(ggplot2)
library(patchwork)
library(ggstance)
df <- data.frame(
trt = c(1,1,2,2),
resp = c(1, 5, 3, 4),
group = factor(c(1, 2, 1, 2)),
upper = c(1.1, 5.3, 3.3, 4.2),
lower = c(0.8, 4.6, 2.4, 3.6)
)

ggplot(df, aes( resp,trt, colour = group))+
geom_linerange(aes(xmin = lower, xmax = upper),
position = position_dodge(width=0.2),orientation ="y")+
geom_text(aes(x=upper,group=interaction(group,trt),label=group),position = position_dodge(width=0.2)) |
ggplot(df, aes( resp,trt, colour = group))+
geom_linerange(aes(xmin = lower, xmax = upper),
position = position_dodge(width=0.2),orientation ="y")+
geom_text(aes(x=upper,group=interaction(group,trt),label=group),position = position_dodgev(height=0.2))

@teunbrand teunbrand added positions 🥇 feature a feature request or enhancement labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement positions 🥇
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants