geom_pointrangeh()-equivalent without ggstance?

79 views
Skip to first unread message

Yuki Takahashi

unread,
Sep 16, 2020, 11:48:09 AM9/16/20
to ggplot2
Dear all,

The ggstance says that ggplot2 version 3.3.0 (and above) now has horizontality support (https://github.com/lionel-/ggstance). What code would allow me to have a geom_pointrangeh()-equivalent graph?

MWE (borrowed from ggeasy question: https://github.com/jonocarroll/ggeasy/issues/20):
library(tidyverse)
library(ggstance)
# create example data frame
df <- data.frame(x = 1:100,
                 group = c(rep(TRUE, 50), rep(FALSE, 50)),
                 v = seq(-4, 4, length.out = 100)) %>%
    mutate(y = tanh(v),
           lower = tanh(v) - 0.2,
           upper = tanh(v) + 0.2)

# the legend key's lines are vertical
ggplot(df, aes(x, y, colour = group)) + geom_pointrange(aes(ymin = lower, ymax = upper)) + coord_flip()

# the legend key's lines are horizontal, but this uses ggstance. How to obtain this graph without using ggstance?
ggplot(df, aes(y, x, colour = group)) + ggstance::geom_pointrangeh(aes(xmin = lower, xmax = upper))

Best,
Yuki

Ben Bolker

unread,
Sep 16, 2020, 11:56:30 AM9/16/20
to ggp...@googlegroups.com
I don't know a way to do what you want (adjust orientation of lines
in the legend) without ggstance. This works without coord_flip:

ggplot(df, aes(y, x, colour = group)) + geom_pointrange(aes(xmin =
lower, xmax = upper))

Another thing I haven't managed to do without ggstance is vertical
dodging (i.e., ggstance::position_dodgev)

This is discussed here:
https://github.com/tidyverse/ggplot2/issues/1389

and here: https://github.com/jonocarroll/ggeasy/issues/20


On 9/16/20 9:51 AM, Yuki Takahashi wrote:
> Dear all,
>
> The ggstance says that ggplot2 version 3.3.0 (and above) now has
> horizontality support (https://github.com/lionel-/ggstance
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_lionel-2D_ggstance&d=DwQFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=zImN_5GfvN5clExGCfuTCw&m=bTMuEPUthoJRJ64EzFGe98grYEc_iT260Nrq-N6DEmI&s=YYA7DQPmjukfV95KUcrR4FZXf5NWnPX5GCb5k1KZO_s&e=>).
> What code would allow me to have a geom_pointrangeh()-equivalent graph?
>
> _MWE (borrowed from ggeasy question:
> https://github.com/jonocarroll/ggeasy/issues/20
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_jonocarroll_ggeasy_issues_20&d=DwQFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=zImN_5GfvN5clExGCfuTCw&m=bTMuEPUthoJRJ64EzFGe98grYEc_iT260Nrq-N6DEmI&s=zbArZ01qHcyHAw3liuP9dzCjNCqgcA0fgxHpr3fX2UA&e=>):_
> library(tidyverse)
> library(ggstance)
> # create example data frame
> df <- data.frame(x = 1:100,
>                  group = c(rep(TRUE, 50), rep(FALSE, 50)),
>                  v = seq(-4, 4, length.out = 100)) %>%
>     mutate(y = tanh(v),
>            lower = tanh(v) - 0.2,
>            upper = tanh(v) + 0.2)
>
> # the legend key's lines are vertical
> ggplot(df, aes(x, y, colour = group)) + geom_pointrange(aes(ymin =
> lower, ymax = upper)) + coord_flip()
>
> # the legend key's lines are horizontal, but this uses ggstance. How to
> obtain this graph without using ggstance?
> ggplot(df, aes(y, x, colour = group)) +
> ggstance::geom_pointrangeh(aes(xmin = lower, xmax = upper))
>
> Best,
> Yuki
>
> --
> --
> You received this message because you are subscribed to the ggplot2
> mailing list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_hadley_devtools_wiki_Reproducibility&d=DwMFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=zImN_5GfvN5clExGCfuTCw&m=bTMuEPUthoJRJ64EzFGe98grYEc_iT260Nrq-N6DEmI&s=BgPS_SDWRgCoDk12N-g8HkJWcFBwBDCWCZSTApO8W14&e=>
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__groups.google.com_group_ggplot2&d=DwMFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=zImN_5GfvN5clExGCfuTCw&m=bTMuEPUthoJRJ64EzFGe98grYEc_iT260Nrq-N6DEmI&s=jhQ4ZJFK05kuQQVWd3xLGv2pzpV8z7NxgR2Q_UloTS0&e=>
>
> ---
> You received this message because you are subscribed to the Google
> Groups "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ggplot2+u...@googlegroups.com
> <mailto:ggplot2+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ggplot2/b9e92c9b-ce9a-4b63-8092-8b33000e64c7n%40googlegroups.com
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_msgid_ggplot2_b9e92c9b-2Dce9a-2D4b63-2D8092-2D8b33000e64c7n-2540googlegroups.com-3Futm-5Fmedium-3Demail-26utm-5Fsource-3Dfooter&d=DwMFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=zImN_5GfvN5clExGCfuTCw&m=bTMuEPUthoJRJ64EzFGe98grYEc_iT260Nrq-N6DEmI&s=bFMtkeo4pSRTOQvrz9tH9dM0j2Ig5aOKUw8wIdbgKAI&e=>.

Yuki Takahashi

unread,
Sep 17, 2020, 7:07:31 AM9/17/20
to Ben Bolker, ggp...@googlegroups.com
Thank you Ben. No, I either don't know why ggstance page says "This package has been superseded by ggplot2 3.3.0, which now has full native support for horizontality."

Best,
Yuki

You received this message because you are subscribed to a topic in the Google Groups "ggplot2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ggplot2/5QemMetN0Jc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ggplot2+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ggplot2/309d0a8a-d9d3-fb50-1903-ebeb386246f6%40gmail.com.

Ben Bolker

unread,
Sep 17, 2020, 12:51:20 PM9/17/20
to ggplot2

Yuki Takahashi

unread,
Sep 17, 2020, 12:59:34 PM9/17/20
to Ben Bolker, ggplot2
Thank you! I will subscribe to the issue.

Yuki

Reply all
Reply to author
Forward
0 new messages