【问题标题】:ggvis density plot + xlim + xlabggvis 密度图 + xlim + xlab
【发布时间】:2014-06-30 13:55:51
【问题描述】:

我正在尝试学习如何使用 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)

感谢您的帮助!

【问题讨论】:

  • 我认为您希望 clamp = TRUE 在您对 scale_numeric 的电话中使用

标签: r ggvis


【解决方案1】:

答案应归功于 hadley,谢谢!

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多