代码之家  ›  专栏  ›  技术社区  ›  tbradley

ggplotly从单个方面删除数据

  •  5
  • tbradley  · 技术社区  · 7 年前

    ggplot 图。当3x2网格中有6个面,左下角再次被放下时,也会发生这种情况。上的示例 plotly ggplot examples page 用2x2网格和显示的数据显示几个示例。我不确定是什么问题。非常感谢您的帮助。

    library(ggplot2)
    library(dplyr)
    library(plotly)
    
    data %>%
      filter(!is.na(result)) %>%
      ggplot(aes(date_time, result)) +
      facet_wrap(~group, scales = "free_y") +
      geom_point() +
      geom_line()
    
    
    ggplotly()
    

    ggplot图 输出: <code>ggplot</code> output

    ggplotly 输出: <code>ggplotly</code> output

    data <- structure(list(group = c("w", "w", "w", "w", "w", "w", "w", 
                                     "w", "w", "w", "w", "w", "w", "w", "w", "w", "w", "w", "w", "w", 
                                     "w", "w", "w", "w", "w", "w", "w", "w", "w", "w", "w", "w", "w", 
                                     "y", "y", "y", "y", "y", "y", "y", "y", "y", "y", "y", "y", "y", 
                                     "y", "y", "y", "y", "y", "y", "y", "y", "y", "y", "y", "y", "y", 
                                     "y", "y", "y", "y", "y", "y", "y", "x", "x", "x", "x", "x", "x", 
                                     "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", 
                                     "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", 
                                     "x", "z", "z", "z", "z", "z", "z", "z", "z", "z", "z", "z", "z", 
                                     "z", "z", "z", "z", "z", "z", "z", "z", "z", "z", "z", "z", "z", 
                                     "z", "z", "z", "z", "z", "z", "z", "z"), 
                       date_time = structure(c(1501581060, 1501668000, 1501752000, 
                                               1501837740, 1502101200, 1502184600, 1502271840, 
                                               1502357280, 1502442720, 1502701860, 1502789280, 
                                               1502876340, 1502961600, 1503047640, 1503305520, 
                                               1503394200, 1503480900, 1503567600, 1503651300, 
                                               1503915120, 1503997800, 1504086300, 1504171920, 
                                               1504259100, 1504607100, 1504691040, 1504777500,
                                               1504865820, 1505122680, 1505211600, 1505296560, 
                                               1505382720, 1505470140, 1501581060, 1501668000, 
                                               1501752000, 1501837740, 1502101200, 1502184600, 
                                               1502271840, 1502357280, 1502442720, 1502701860, 
                                               1502789280, 1502876340, 1502961600, 1503047640, 
                                               1503305520, 1503394200, 1503480900, 1503567600, 
                                               1503651300, 1503915120, 1503997800, 1504086300, 
                                               1504171920, 1504259100, 1504607100, 1504691040, 
                                               1504777500, 1504865820, 1505122680, 1505211600, 
                                               1505296560, 1505382720, 1505470140, 1501581060, 
                                               1501668000, 1501752000, 1501837740, 1502101200, 
                                               1502184600, 1502271840, 1502357280, 1502442720, 
                                               1502701860, 1502789280, 1502876340, 1502961600, 
                                               1503047640, 1503305520, 1503394200, 1503480900, 
                                               1503567600, 1503651300, 1503915120, 1503997800, 
                                               1504086300, 1504171920, 1504259100, 1504607100, 
                                               1504691040, 1504777500, 1504865820, 1505122680, 
                                               1505211600, 1505296560, 1505382720, 1505470140, 
                                               1501581060, 1501668000, 1501752000, 1501837740, 
                                               1502101200, 1502184600, 1502271840, 1502357280, 
                                               1502442720, 1502701860, 1502789280, 1502876340, 
                                               1502961600, 1503047640, 1503305520, 1503394200, 
                                               1503480900, 1503567600, 1503651300, 1503915120, 
                                               1503997800, 1504086300, 1504171920, 1504259100, 
                                               1504607100, 1504691040, 1504777500, 1504865820, 
                                               1505122680, 1505211600, 1505296560, 1505382720, 
                                               1505470140), 
                                             class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
                       result = c(2.1, 1.75, 1.65, 1.65,  1.75, 1.65, 1.3, 1.65, 1.9, 1.6, 1.65, 
                                  1.35, 1.6, 1.85, 2.05,  1.95, 2, 1.95, 1.9, 1.9, 2.05, 2, 2, 
                                  2, 2.1, 2.1, 2, 2.05, 2.05, 2.3, 2.2, 2, NA, 7.14, 7.1, 7.09, 
                                  7.09, 7.13, 7.12, 7.13, 7.07, 7.04, 7.06, 7.12, 7.08, 7.06, 
                                  7.07, 7.05, 7.05, 7.1, 7.09, 7.06, 7.18, 7.16, 7.11, 7.17, 
                                  7.14, 7.13, 7.08, 7.11, 7.09, 7.12, 7.05,  7.08, 7.02, 7.12, 
                                  0.214, 0.181, 0.357, 0.49, 0.294, 0.369, 0.406, 0.325, 0.197, 
                                  0.36, 0.358, 0.408, 0.37, 0.254, 0.24, 0.178, 0.201, 0.166, 0.203, 
                                  0.163, 0.147, 0.177, 0.155, 0.177, 0.133, 0.133, 0.182, 0.203, 
                                  0.161, 0.151, 0.171, 0.117, NA, 26, 26, 26, 26, 25, 26, 25, 26, 
                                  26, 26, 26, 25, 26, 26, 25, 26, 26, 26, 26, 26, 26, 26, 26, 25, 
                                  25, 24, 24, 24, 23, 23, 23, 24, 23)), 
                  .Names = c("group", "date_time", "result"), 
                  class = c("tbl_df", "tbl", "data.frame"), 
                  row.names = c(NA, -132L))
    
    1 回复  |  直到 7 年前
        1
  •  5
  •   Marco Sandri    7 年前

    可能这是 ggplotly
    scales="free" 在…内 facet_wrap

    p <- data %>%
      filter(!is.na(result)) %>%
      ggplot(aes(date_time, result)) +
      facet_wrap(~group, scales = "free") +
      geom_point() +
      geom_line()
    
    g <- plotly_build(p)
    # Set "x3" axis as common x-axis of Plot 1 and 3 
    g$x$data[[1]]$xaxis <- "x3"
    # Set "x4" axis as common x-axis of Plot 2 and 4
    g$x$data[[2]]$xaxis <- "x4"
    print(g)
    

    enter image description here here here