我正在尝试学习如何使用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)
感谢您的帮助!
答案 0 :(得分:5)
答案应该归功于哈特利,谢谢!
mtcars %>% ggvis(~wt, fill := "red") %>%
layer_densities() %>%
add_axis("x", title = "Weight") %>%
scale_numeric("x", domain = c(0, 5), nice = FALSE, clamp = TRUE)