简体   繁体   English

直方图中y轴的奇怪行为

[英]Strange behavior of y axis in histograms

I want to put a set of histograms of different variables all on the same scaled y axis using ggivs. 我想使用ggivs将一组不同变量的直方图全部放在同一比例的y轴上。 However, once my axes get meaningfully larger than the highest count for a variable they start to get very strange and even start plotting the bars in a negative direction. 但是,一旦我的轴有意义地大于某个变量的最高计数,它们就会开始变得非常奇怪,甚至开始以负方向绘制条形图。 This is with my data http://rpubs.com/elinw/116698 这是我的数据http://rpubs.com/elinw/116698

Here is a reproducable example 这是一个可复制的示例

# no values specified
iris %>% ggvis(~Sepal.Width) %>% layer_histograms(width = 1)  %>%
   add_axis("y", title = "Count", title_offset="50") 
   add_axis("x", title = "Width", title_offset="50") 

#0 to 150
 iris %>% ggvis(~Sepal.Width) %>% layer_histograms(width = 1)  %>%
   add_axis("y", title = "Count", title_offset="50",  values = seq(0,150, by = 10))  %>%
   add_axis("x", title = "Width", title_offset="50") 

  #0 to 175
 iris %>% ggvis(~Sepal.Width) %>% layer_histograms(width = 1)  %>%
   add_axis("y", title = "Count", title_offset="50",  values = seq(0,200, by = 10))  %>%
   add_axis("x", title = "Width", title_offset="50") 

 #0 to 250
 iris %>% ggvis(~Sepal.Width) %>% layer_histograms(width = 1)  %>%
   add_axis("y", title = "Count", title_offset="50",  values = seq(0,250, by = 10))  %>%
   add_axis("x", title = "Width", title_offset="50") 

#0 to 500
 iris %>% ggvis(~Sepal.Width) %>% layer_histograms(width = 1)  %>%
   add_axis("y", title = "Count", title_offset="50",  values = seq(0,500, by = 10)) 
   add_axis("x", title = "Width", title_offset="50") 

I've read the documentation but I don't see anything about this. 我已经阅读了文档,但是对此一无所获。 Is there something in the properties that I can change to make this work? 我可以更改属性以使其正常工作吗? Or is there a known rule about this? 还是对此有一个已知的规则? Or is it a bug? 还是一个错误?

The argument values in add_axis only sets where the ticks are on the axis, but it does not change the minimal and maximal limits of the axis (ylim/xlim). add_axis的参数values仅设置刻度线在轴上的位置,但不会更改轴的最小和最大限制(ylim / xlim)。 According to ggvis doc , you need to set those with argument domain in scale_numeric() . 根据ggvis doc ,您需要在scale_numeric()设置参数为domain参数。 Try this: 尝试这个:

iris %>% ggvis(~Sepal.Width) %>% layer_histograms(width = 1)  %>%
  add_axis("y", title = "Count", title_offset="50",  values = seq(0,150, by = 10))  %>%
  ## Set axis limits:
  scale_numeric("y", domain = c(0, 150), nice = FALSE) %>% 
  add_axis("x", title = "Width", title_offset="50")

You can see all the plots here: http://rpubs.com/scoa/116718 您可以在此处查看所有图: http : //rpubs.com/scoa/116718

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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