【问题标题】:ggplot : Hide geom_ribbon by default to my plotggplot :默认隐藏geom_ribbon到我的情节
【发布时间】:2018-09-27 09:37:30
【问题描述】:

我有这个情节:

g.mean <- ggplot(df,aes(x = as.numeric(xx),y=yy,color=varc)) + 
      geom_line() +
      geom_ribbon(aes(ymin=Born_Inf, ymax=Born_Sup, fill=varc), alpha=0.1)

有没有办法只隐藏 geom_ribbon() 并将 geom_line() 打印到我的图表中?我尝试使用“legendonly”,但这会隐藏所有行...

style(ggplotly(g.mean, tooltip = c("varc")), hoverinfo = "value",visible="legendonly")  #,traces = 1

【问题讨论】:

  • 不确定我是否理解您所说的 “仅隐藏 geom_ribbon 是什么意思。如果你不想要geom_ribbon 为什么不直接删除它?
  • 默认情况下我想隐藏 geom_ribbon 因为“填充”参数中的 varc 有很多因素(10 个因素)。所有 geom_ribbon 因素的情节都不清楚。我想选择打印某些因素的置信区间,但默认情况下不打印

标签: r ggplot2 ggplotly r-plotly


【解决方案1】:

在函数“style()”中隐藏带有参数“traces”的 geom_ribbon()。例如:我的 varC 中有 10 个因子,所以我有 10 行 (geom_line()) 和 10 CI (geom_ribbon):20 项。

隐藏 geom_ribbon() 表示“traces” 11:20 和 visible="legendonly"

style(ggplotly(g.mean, tooltip = c("varC","x","y")),
  visible="legendonly",
  hoverinfo = "value",
  traces = c((length(unique(df$varC))+1):(length(unique(df$varC))*2)))

【讨论】:

    猜你喜欢
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 2013-09-23
    • 2020-01-12
    • 1970-01-01
    相关资源
    最近更新 更多