stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 269 forks source link

rstan plot error with ggplot2 2.2.0 #357

Closed jasonqiangguo closed 7 years ago

jasonqiangguo commented 7 years ago

Summary:

traceplot(stan.fit, pars='theta', ask=TRUE) Warning: Ignoring unknown parameters: ask Error in [.unit(padding, 4) : index out of bounds ('unit' subsetting)

Description:

My ggplot2 version is the development version of ggplot2 (2.2.0) and when I want to briefly check the convergence using traceplot. But it gave me an error as above. Any solution?

RStan Version:

package ‘rstan’ was built under R version 3.2.5

R Version:

R version 3.2.4

Operating System:

Your operating system (e.g., OS X 10.11.6)

jgabry commented 7 years ago

Hi Jason,

The latest ggplot2 isn't fully compatible with the current rstan release. We will fix that (it might already be working on the develop branch of rstan), but in the meantime you can use our new bayesplot package (now on CRAN). If you have bayesplot loaded you can do:

draws <- as.array(stan.fit, pars="theta") mcmc_trace(draws)

On Tue, Nov 29, 2016 at 10:21 PM Jason Qiang Guo notifications@github.com wrote:

Summary:

traceplot(stan.fit, pars='theta', ask=TRUE) Warning: Ignoring unknown parameters: ask Error in [.unit(padding, 4) : index out of bounds ('unit' subsetting)

Description:

My ggplot2 version is the development version of ggplot2 (2.2.0) and when I want to briefly check the convergence using traceplot. But it gave me an error as above. Any solution? RStan Version:

package ‘rstan’ was built under R version 3.2.5 R Version:

R version 3.2.4 Operating System:

Your operating system (e.g., OS X 10.11.6)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/357, or mute the thread https://github.com/notifications/unsubscribe-auth/AHb4Q5wmkTvg9ILH44q6i1z_o-Mt3fmoks5rDOuggaJpZM4K_wsV .

wds15 commented 7 years ago

Hi!

I am using a similar technique as rstan does in another package and had the same trouble with ggplot2 2.2.0, To me it looks as if the problem is in ggplot2, but can be easily fixed from the rstan side. When you define the theme object, you do right now something like

.rstanvis_defaults <- new.env(parent = emptyenv())
.rstanvis_defaults$theme <- theme_bw(... some options...)

Changeing this to

.rstanvis_defaults <- new.env(parent = emptyenv())
.rstanvis_defaults$theme <- theme_bw(...some options..., base_size = 11, base_family = "Arial")

makes it work again - at least for me, So you have to explicitly specify the base_size and base_family option, the default does trigger the stupid mistake.

Hope that helps.

jgabry commented 7 years ago

Thanks for the tip!

On Fri, Dec 9, 2016 at 11:12 AM wds15 notifications@github.com wrote:

Hi!

I am using a similar technique as rstan does in another package and had the same trouble with ggplot2 2.2.0, To me it looks as if the problem is in ggplot2, but can be easily fixed from the rstan side. When you define the theme object, you do right now something like

.rstanvis_defaults <- new.env(parent = emptyenv())

.rstanvis_defaults$theme <- theme_bw(... some options...)

Changeing this to

.rstanvis_defaults <- new.env(parent = emptyenv())

.rstanvis_defaults$theme <- theme_bw(...some options..., base_size = 11, base_family = "Arial")

makes it work again - at least for me, So you have to explicitly specify the base_size and base_family option, the default does trigger the stupid mistake.

Hope that helps.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/357#issuecomment-266052652, or mute the thread https://github.com/notifications/unsubscribe-auth/AHb4Q_sU1ENuqLnh1J52MJZNB9-QL_mYks5rGX4BgaJpZM4K_wsV .

jasonqiangguo commented 7 years ago

Thank you so much for the tip!

petyaracz commented 1 year ago

I seem to have the same problem six years later.

fit = stan_glm(Sepal.Width ~ Sepal.Length, data = iris)

fit
> stan_glm
> family:       gaussian [identity]
> formula:      Sepal.Width ~ Sepal.Length
> ...
# yes it fit

plot(fit)

> Error in element_line(...) : unused argument (linewidth = 1)
> In addition: Warning messages:
> 1: Ignoring unknown parameters: linewidth 
> 2: Ignoring unknown parameters: linewidth 
> 3: Ignoring unknown parameters: linewidth 

R version 4.2.2 (2022-10-31)

bayesplot_1.10.0 rstanarm_2.21.3

EDIT: resolved with ggplot2_3.4.0