require(rms)
require(plotly)
set.seed(1)   # so can reproduce
x1 <- runif(100)
x2 <- runif(100)
x3 <- sample(c('a','b'), 100, TRUE)
x4 <- sample(c('k','l','m'), 100, TRUE)
y <- runif(100)
dd <- datadist(x1, x2, x3, x4); options(datadist='dd')
f <- ols(y ~ x1 + x2 + x3 + x4)

Using ggplotly on ggplot.Predict object

This method works fine.

options(grType=NULL)
g <- ggplot(Predict(f,x1))
ggplotly(g)
z <- 900
g <- ggplot(Predict(f,x1))
ggplotly(g, height=z, width=z)

This

ggplot(Predict(f,x1))

That

Using plotly_build on ggplot.Predict object

You see that when a plot is large, it covers the next output area.

b <- function(g, h=NULL, w=NULL) {
  a <- plotly_build(g)
    if(length(h)) {
      a$layout$height <- h
        a$layout$width  <- w
        }
    a
    }
g <- ggplot(Predict(f,x1))
b(g)
z <- 900
g <- ggplot(Predict(f,x1))
b(g, h=z, w=z)

This

ggplot(Predict(f,x1))

That

Using ggplotly within ggplot.Predict

This worked fine.

options(grType='plotly')
ggplot(Predict(f,x1))
z <- 1200
ggplot(Predict(f,x1), height=z, width=z)

This

ggplot(Predict(f,x1))

That

Repeat for more complex ggplot output

1200 at 72 dpi is 16.67 inches. Tex and histogram were cut off if figure size was omitted from chunk header.

ggplot(Predict(f), sepdiscrete='vertical', height=z, width=z)

And here is ...

More stuff ....

hist(rnorm(1000))


harrelfe/rms documentation built on March 19, 2024, 3:27 a.m.