7

I want my ggvis plots to have a specific height and width.

Adding %>% set_options(height = 480, width = 480) sizes only the actual plot, i.e. the grid with the data is 480x480. I want to be able to specify the dimensions of the entire image, including axes, ticks and labels.

Any suggestions?

EDIT: A full example:

library(ggvis)
mtcars %>% 
    ggvis(~hp,~wt) %>% 
    layer_points() %>% 
    set_options(height = 480, width = 480)
filipsch
  • 195
  • 1
  • 10
  • Were you able to find a solution to this issue? – glnvdl Jul 04 '15 at 19:23
  • I decided to hack some of the js files that come with ggvis, so that my plot automatically adjusts to the container it's embedded in; that did it for me, but is not at all a generally applicable solution... – filipsch Mar 04 '16 at 13:39

1 Answers1

0

You can accomplish this by using properties. For example, you can control the size of the axes, ticks and labels like this -

library(ggvis)

mtcars %>% 
  ggvis(~hp,~wt) %>% 
  layer_points() %>% 
  set_options(height = 480, width = 480) %>%
  add_axis("x", title = "whatever", properties = axis_props(
    axis = list(stroke = "red", strokeWidth = 3),
    grid = list(stroke = "blue"),
    ticks = list(stroke = "green", strokeWidth = 10),
    labels = list(angle = 45, align = "left", fontSize = 10),
    title = list(fontSize = 40)
  ))

You can find more info from - http://ggvis.rstudio.com/axes-legends.html

"Finally, both axes and legends share properties, which is a named list of props() that is applied to specified components of the axis or legend. For axes, you can set the properties of the ticks (or majorTicks and minorTicks separately), the labels and axis. For legends, you can set properties of the title, label, symbols (for categorical scales), gradient (for continuous scales), and legend."

nafizh
  • 185
  • 3
  • 14
  • when I change width = 2000 it does not change the plot at all. I need to plot in landscape on A3 paper and take advantage of large width. (or scrollable large PNG). – userJT Jan 25 '16 at 20:05