【问题标题】:R ggvis: How do I increase layer_arc size?R ggvis:如何增加 layer_arc 大小?
【发布时间】:2015-05-13 23:23:27
【问题描述】:

我需要一些帮助来了解如何使 ggvis 标记(在本例中为 layer_arcs)更大

我一直在尝试在 R(v3.2.0,Windows 7)的ggvis(v0.4.1)中重新创建一个旭日形图,并设法创建了一个 data.frame “df_example”,其中每一行都是一个弧标记和适当的参数与 layer_arc 一起使用。以下是 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 ...

现在,当我使用 ggvis 使用以下代码进行绘制时:

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))

我得到这样的图像:

我不确定如何使标记整体更大(基本上使整个视觉尽可能多地占据空间)。我尝试增加内/外半径并更改 x/y 比例,但这不会改变弧线标记的外观尺寸。我觉得这与比例有关(例如,半径以像素为单位)。关于我缺少哪些参数以及其他任何内容的任何指针都会有所帮助。

【问题讨论】:

    标签: r ggvis


    【解决方案1】:

    我知道这个问题已经很老了,但我遇到了类似的问题,并提出了一些可能对其他人有帮助的意见:

    # 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"  )
    

    1) 调整 x 和 y 域,使绘图居中

    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
    

    2) 通过使用“=~”,您可以将数据映射到它的比例,如果您使用“:=~”,您可以定义实际的像素大小

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

    这样您就可以根据需要定义大小。

    3) 如果你想让绘图设备为你处理比例,你必须改变半径的比例。现在我不完全知道这里发生了什么: 调整域值我能够让绘图很好地填充绘图区域。 (减小域会使图变大,而增大域会使图变小)。然而,情节将被裁剪掉,例如如果您更改大小或从 R Studio 导出,则闪亮:

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

    【讨论】:

      猜你喜欢
      • 2016-04-23
      • 1970-01-01
      • 2011-05-25
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      相关资源
      最近更新 更多