简体   繁体   中英

Set height and width of entire ggvis plot, including axes and axis labels

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

Adding %>% set_options(height = 480, width = 480) sizes only the actual plot, ie 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)

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."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM