Is there a way to plot both horizontal and vertical point ranges together on the same plot in ggplot
. I understand that geom_pointrange(...)
plots vertical point ranges, and that horizontal point ranges can be generated with coord_flip(...)
, but I'm interested in putting both together on the same plot.
set.seed(1)
df <- data.frame(x=sample(1:10,10),y=sample(1:10,10), x.range=1, y.range=2)
library(ggplot2)
ggplot(df) +
geom_pointrange(aes(x=x, y=y, ymin=y=y.range, ymax=y+y.range))
I'm looking for something like this:
ggplot(df) +
geom_pointrange(aes(x=x, y=y,
ymin=y-y.range, ymax=y+y.range,
xmin=x-x.range, xmax=x+x.range))
Which of course produces the same output as above because the xmin
and xmax
arguments are ignored. Evidently, there is (was) a function geom_hpointrange(...)
in ggExtra
, but this package has been pulled as far as I can tell.
Is geom_errorbarh
what you are looking for?
ggplot(data = df, aes(x = x, y = y)) +
geom_pointrange(aes(ymin = y - y.range, ymax = y + y.range)) +
geom_errorbarh(aes(xmax = x + x.range, xmin = x - x.range, height = 0))
you can also call geompoint_range twice
ggplot(df, aes(x=x, y=y)) +
geom_pointrange(aes(ymin=y-y.range, ymax=y+y.range)) +
geom_pointrange(aes(xmin=x-x.range, xmax=x+x.range))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With