Expanding axis limits in bayesplot (mcmc_intervals and mcmc_areas)

376 views
Skip to first unread message

Björn Holzhauer

unread,
May 23, 2017, 12:25:36 PM5/23/17
to Stan users mailing list
Hi all,

I trying the bayesplot R package and it's great. In some plots, I want to include certain parameter values in the plot, even if they lie totally outside of all the posterior sample values drawn or intervals being plotted. E.g. in the example below always make sure the x-axis includes a log-hazard ratio of 0 (no treatment effect). I could not find anything in the bayesplot documentation, but got the impression that most ggplot2 concepts should carry over

So I tried the following, which does not seem to work
mcmc_intervals(posterior1, pars = c("logHR")) + expand_limits(x = 0)
(nor  does
plot1 <- mcmc_intervals(posterior1, pars = c("logHR"))
plot1 + expand_limits(x = 0)
).

It works for mcmc_hex and mcmc_violin, while it also (like for mcmc_intervals) does not work for mcmc_areas.

Is that something that should work somehow or is this a deliberate feature or is that a possible future feature that is not available at the moment?

Many thanks,
Björn

Jonah Gabry

unread,
May 23, 2017, 1:09:15 PM5/23/17
to Stan users mailing list
Hi Bjorn, 

For future reference, we're moving the Stan forum over to Discourse (new location is http://discourse.mc-stan.org), but I'll answer this one here. To get mcmc_intervals/areas to look how I wanted I had to code those functions a bit differently than the others, so maybe that's why expand_limits isn't working. I'll have to look into that a bit to see what exactly the issue is. In the meantime, ggplot2's other functions for changing axis limits should work. So you could use xlim(), or the xlim argument to coord_cartesian(), etc. For example, you should be able to do plot1 + xlim(a, b) and if a<=0<=b then that should force the plot to include 0. 

Jonah

Björn Holzhauer

unread,
May 24, 2017, 4:10:51 AM5/24/17
to stan-...@googlegroups.com
Thanks,

that solved my problem.

Best Regards,
Björn

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/PFN1-95Y92o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonah Sol Gabry

unread,
May 24, 2017, 4:05:08 PM5/24/17
to stan-...@googlegroups.com
No problem! Glad the package has been useful. 

Jonah

On Wed, May 24, 2017 at 4:10 AM Björn Holzhauer <bjoernh...@gmail.com> wrote:
Thanks,

that solved my problem.

Best Regards,
Björn
On 23 May 2017 at 19:09, Jonah Gabry <jga...@gmail.com> wrote:
Hi Bjorn, 

For future reference, we're moving the Stan forum over to Discourse (new location is http://discourse.mc-stan.org), but I'll answer this one here. To get mcmc_intervals/areas to look how I wanted I had to code those functions a bit differently than the others, so maybe that's why expand_limits isn't working. I'll have to look into that a bit to see what exactly the issue is. In the meantime, ggplot2's other functions for changing axis limits should work. So you could use xlim(), or the xlim argument to coord_cartesian(), etc. For example, you should be able to do plot1 + xlim(a, b) and if a<=0<=b then that should force the plot to include 0. 

Jonah

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/PFN1-95Y92o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.

To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/PFN1-95Y92o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages