0

I need some help in understanding how to make ggvis marks (in this case layer_arcs) bigger

I've been trying to recreate a sunburst diagram in ggvis (v0.4.1) in R (v3.2.0, Windows 7) and have managed to create a data.frame "df_example" where each row is an arc mark and appropriate parameters to use to with layer_arc. Below is a sample of the data.frame:

str(df_example)
'data.frame':   47 obs. of  6 variables:
 $ innerRadius: num  50 50 50 50 50 50 50 100 100 100 ...
 $ outerRadius: num  100 100 100 100 100 100 100 150 150 150 ...
 $ stopAngle  : num  0.0991 0.2861 0.5329 0.7838 1.0955 ...
 $ initAngle  : num  0 0.0991 0.2861 0.5329 0.7838 ...
 $ x          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ y          : num  0 0 0 0 0 0 0 0 0 0 ...

Now when I plot this using ggvis with the following code:

df_example %>%
  ggvis(x=~x,y=~y) %>%
  layer_arcs(innerRadius=~innerRadius,outerRadius=~outerRadius,
             startAngle=~initAngle,endAngle=~stopAngle,
             stroke:="white",fill.hover:="#AAFFAA") %>%
  scale_numeric("x",domain=c(-10,10)) %>%
  scale_numeric("y",domain=c(-10,10))

I get an image like this: enter image description here

I'm unsure how to go about making the marks bigger overall (essentially making the whole visual take up as much as space as possible). I've tried increasing the inner/outer radii and changing the x/y scales but that doesn't change the apparent size of the arc marks. I feel this has something to do with the scales (radii are in pixels for example). Any pointers as to what parameters I'm missing and anything else would be helpful.

1 Answers1

2

I know this question is quite old, but I had a similar problem and made a couple observations that might be helpful for others:

# example data
library(ggvis)
df <- data.frame(
  init = c(0), end = c(2*pi), 
  inner = c(10), outer = c(100),
  x = 0.5, y =0.5
) 

# all wrong
df %>% 
  ggvis(~x,~y) %>% 
  layer_arcs(
    startAngle =~init, endAngle =~end, innerRadius =~ inner, outerRadius =~outer, 
    stroke:="white",fill.hover:= "#AAFFAA"  )

enter image description here

1) adjust the x and y domain so it centers the plot

df %>% 
  ggvis(~x,~y) %>% 
  layer_arcs(
    startAngle =~init, endAngle =~end, innerRadius =~ inner, outerRadius =~outer, 
    stroke:="white",fill.hover:= "#AAFFAA"  ) %>% 
  scale_numeric("x", domain = c(0,1)) %>% 
  scale_numeric("y", domain = c(0,1)) %>% 
  hide_axis("x") %>% 
  hide_axis("y") 
# getting there, but still off

enter image description here

2) By using "=~" you map the data to it's scale if you use ":=~" you can define the actual pixel size

df %>% 
  ggvis(~x,~y) %>% 
  layer_arcs(
    startAngle =~init, endAngle =~end, innerRadius :=~ inner, outerRadius :=~outer, 
    stroke:="white",fill.hover:= "#AAFFAA"  ) %>% 
  scale_numeric("x", domain = c(0,1)) %>% 
  scale_numeric("y", domain = c(0,1)) %>% 
  hide_axis("x") %>% 
  hide_axis("y") 

enter image description here

That way you can define the size as you wish.

3) If you want the drawing device to handle the scales for you, you have to alter the scale of radius. Now I don't exactly know whats going on here: Adjusting the domain values I was able to have the plot fill out the plotting area quite nicely. (Decreasing domain made the plot larger, whereas increasing it makes it smaller). However the the plot will be cropped out in e.g. shiny if you change the size or export from R studio:

enter image description here

 df %>% 
  ggvis(~x,~y) %>% 
  layer_arcs(
    startAngle =~init, endAngle =~end, innerRadius =~ inner, outerRadius =~outer, 
    stroke:="white",fill.hover:= "#AAFFAA"  ) %>% 
  scale_numeric("radius", domain = c(0, (100 - 10) / 2 / pi)) %>% 
  scale_numeric("x", domain = c(0,1)) %>% 
  scale_numeric("y", domain = c(0,1)) %>% 
  hide_axis("x") %>% 
  hide_axis("y")
plastikdusche
  • 235
  • 2
  • 10