2014-06-30 27 views
2

我在学习如何使用ggvis。基本上,我想重现此GGPLOT2图:ggvis密度图+ xlim + xlab

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

我觉得你想在调用'scale_numeric'时使用'clamp = TRUE' – hadley

回答

4

答案的信用应该去哈德利,谢谢!

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