3

我正在尝试学习如何使用 ggvis。基本上,我想重现这个 ggplot2 图:

library(ggplot2)
m <- ggplot(mtcars, aes(x = wt))
m + geom_density(aes(fill="orange"), size=2, alpha=.9) + xlim(0,5) + theme_bw() + 
  xlab("x label") + guides(fill=FALSE)

现在我有这个:

mtcars %>% ggvis(~wt, fill := "red") %>% 
  layer_densities() %>%  
  add_axis("x", title = "Weight") %>% 
  scale_numeric("x", domain = c(0, 5), nice = FALSE)

但我不知道怎么做 xlim(0,5)

谢谢您的帮助!

4

1 回答 1

5

答案的学分应该归哈德利所有,谢谢!

mtcars %>% ggvis(~wt, fill := "red") %>% 
  layer_densities() %>%  
  add_axis("x", title = "Weight") %>% 
  scale_numeric("x", domain = c(0, 5), nice = FALSE, clamp = TRUE)
于 2014-06-30T15:06:25.263 回答