ggvis密度图+ xlim + xlab

Ign*_*cio 3 r ggvis

我正在努力学习如何使用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)
Run Code Online (Sandbox Code Playgroud)

现在我有这个:

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

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

谢谢您的帮助!

Ign*_*cio 5

答案应该归功于哈特利,谢谢!

mtcars %>% ggvis(~wt, fill := "red") %>% 
  layer_densities() %>%  
  add_axis("x", title = "Weight") %>% 
  scale_numeric("x", domain = c(0, 5), nice = FALSE, clamp = TRUE)
Run Code Online (Sandbox Code Playgroud)