我試圖做一個動態的情節,即我將時間滑塊移動和顯示我的值XVAR,并YVAR在其他時間,我已經得到了。我另外需要的是圖中的那些點有一個垂直段到它們各自的高度,即從這個

對此:

有人告訴我geom_segment()可以這樣做,但我不明白如何管理xend和yend引數以使段的位置正確。
到目前為止,這是我的代碼:
library(plotly)
library(tidyverse)
XVAR<-seq(from=1,to=10)
Time<-seq(from=1,to=10)
dat2<-expand_grid(XVAR,Time)
set.seed(1)
dat2$YVAR<-runif(100,0,10)
pl <-
ggplot(dat2, aes(x=XVAR,y=YVAR, frame = Time))
geom_point()
ggplotly(pl)
任何幫助,將不勝感激。非常感謝。
uj5u.com熱心網友回復:
你可以這樣使用geom_segment。
pl <- ggplot(dat2, aes(x=XVAR,y=YVAR, frame = Time))
geom_point()
geom_segment(aes(x = XVAR, xend = XVAR, y = 0, yend = YVAR), color = "red")
ggplotly(pl)

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/335793.html
上一篇:使用影像作為點ggplot2
