代码之家  ›  专栏  ›  技术社区  ›  Mus mzuba

为什么我的风水物体不出现在我的图上?

  •  0
  • Mus mzuba  · 技术社区  · 6 年前

    我已经研究了许多解决其他人与同一问题有关的问题的方法,但到目前为止没有任何方法对我有效。

    我想要一条垂直线出现在“2018-07-23”上,这个代码是我得到的最接近的(因为它不会产生错误):。

    ggplot(分组)+
    几何线条(aes(x=日期,y=站点宽度,组=1)
    linetype=“虚线”,
    colour=“森林绿”,
    α= 0.5)+
    几何线条(aes(x=日期,y=主页打开,组=1)
    colour=“蓝色”)。+
    geom-vline(aes(xintercept=as.date(分组$date[8]),
    线型=4,colour=“black”)
    < /代码> 
    
    

    grouped$date的格式是character,这就是我将其转换为date的原因。请注意,我得到的结果与as.posixcttoo相同(非-)。

    我哪里出错了?

    我的数据框:

    grouped<-structure(list(date=c)(“2018-07-16”,“2018-07-17”,“2018-07-18”,
    “2018-07-19”、“2018-07-20”、“2018-07-21”、“2018-07-22”、“2018-07-23”,
    “2018-07-24”、“2018-07-25”、“2018-07-26”、“2018-07-27”、“2018-07-28”,
    “2018-07-29”、“2018-07-30”、“2018-07-31”),主页打开=C(5L,
    0升,0升,3升,1升,2升,0升,1升,0升,2升,5升,0升,0升,0升,0升,
    全场开放=C(39L,34L,19L,62L,46L,44L,16L,51L,
    25L,66L,75L,0L,0L,0L,0L,0L),开始聊天=C(10L,
    16升、9升、8升、13升、13升、5升、13升、4升、8升、11升、0升、0升、0升,
    0L,0L),聊天完成=C(7L,13L,8L,4L,5L,9L,6L,
    13L,2L,7L,5L,0L,0L,0L,0L,0L)),C级(“tbl_df”,
    “tbl”,“data.frame”),row.name=c(na,-16l)
    < /代码> 
    
    

    我的图表:

    =

    ggplot(grouped) +
      geom_line(aes(x = date, y = sitewide_opens, group = 1),
                linetype = "dashed",
                colour = "forestgreen",
                alpha = 0.5) +
      geom_line(aes(x = date, y = homepage_opens, group = 1),
                colour = "blue") +
      geom_vline(aes(xintercept = as.Date(grouped$date[8])),
                 linetype = 4, colour = "black")
    

    格式grouped$date是字符,这就是我将其转换为日期的原因。请注意,我得到的结果与as.POSIXct也是。

    我哪里出错了?

    我的数据帧:

    grouped <- structure(list(date = c("2018-07-16", "2018-07-17", "2018-07-18", 
    "2018-07-19", "2018-07-20", "2018-07-21", "2018-07-22", "2018-07-23", 
    "2018-07-24", "2018-07-25", "2018-07-26", "2018-07-27", "2018-07-28", 
    "2018-07-29", "2018-07-30", "2018-07-31"), homepage_opens = c(5L, 
    0L, 0L, 3L, 1L, 2L, 0L, 1L, 0L, 2L, 5L, 0L, 0L, 0L, 0L, 0L), 
        sitewide_opens = c(39L, 34L, 19L, 62L, 46L, 44L, 16L, 51L, 
        25L, 66L, 75L, 0L, 0L, 0L, 0L, 0L), chats_started = c(10L, 
        16L, 9L, 8L, 13L, 13L, 5L, 13L, 4L, 8L, 11L, 0L, 0L, 0L, 
        0L, 0L), chats_completed = c(7L, 13L, 8L, 4L, 5L, 9L, 6L, 
        13L, 2L, 7L, 5L, 0L, 0L, 0L, 0L, 0L)), class = c("tbl_df", 
    "tbl", "data.frame"), row.names = c(NA, -16L))
    

    我的图表:

    2 回复  |  直到 6 年前
        1
  •  0
  •   AlienDeg    6 年前
        2
  •  1
  •   heck1    6 年前

    grouped$date

    ggplot(grouped) +
      geom_line(aes(x = as.Date(grouped$date), y = sitewide_opens, group = 1),
            linetype = "dashed",
            colour = "forestgreen",
            alpha = 0.5) +
            geom_line(aes(x =  as.Date(grouped$date), y = homepage_opens, group = 1),
            colour = "blue") +
           geom_vline(aes(xintercept = as.Date(grouped$date[8])),
             linetype = 4, colour = "black")
    

    https://i.imgur.com/Km8UvaX.jpg

    推荐文章