[英]Add layer underneath interactive layer with ggvis
I want to use the tooltip function within ggvis to create hover text for specific points along a curve. 我想在ggvis中使用工具提示功能为曲线上的特定点创建悬停文本。 I can get the plot to form, but the text in the hover field won't show up.
我可以形成图表,但是悬停字段中的文本不会显示。 This occurs when I try to add a background layer that should not be considered part of the interactive part of the visualization.
当我尝试添加不应被视为可视化交互部分的背景层时,就会发生这种情况。 Below is some code illustrating:
以下是一些代码说明:
library(ggvis)
# one-compartment oral concentration curve
comp1.oral <- function(ka,ke,v,f,dose,time){
(ka * dose * f)/ (v*(ka-ke)) * (exp(-ke * time) - exp(-ka*time))
}
time <- 0:200 # time points to create curve
tp <- 6 # number of times to sample
tmax <- max(time)
#generically choosing tp points to sample at
tnew <- exp(seq(0,log(tmax),length=(tp)))
#computing the concentration (y value)
y <- comp1.oral(.1,.03,4,1,100,tnew)
#creating dataframe with values
# PK and ECG should be in the hover text
d1 <- data.frame(
Conc= y,
Time=tnew,
PK = 1:tp,
ECG= "No"
)
# creating a column with the text to appear in the hover box
d1$long <- paste0("PK: ",d1$PK,"<br>","ECG: ",d1$ECG,"<br>")
#creating another data frame to input the time-conc curve as a background layer
d2 <- data.frame(
x=time,
y=comp1.oral(.1,.03,4,1,100,time)
)
The code below will form the plot I want but without the hover text. 下面的代码将形成我想要的情节,但没有悬停文本。
d1 %>%
ggvis(x = ~Time, y=~Conc) %>%
layer_points(size.hover:=200) %>%
layer_paths(~x,~y,data=d2) %>%
add_tooltip(function(d1){
if (!is.null(d1$Time)) paste0("PK:", "<br>ECG:", "<br>Time: ", as.character(round(d1$Time)), " minutes post-dose")
}, "hover")
I would like to get the otehr values from d1$long into the hover text box. 我想从d1 $ long中获取otehr值到悬停文本框中。 I tried adding it similar to what is seen in the rotten tomatoes shiny example, but it wouldn't work.
我尝试将其添加到类似于烂番茄发亮的示例中所看到的内容,但是它不起作用。
I tried the following, but it can't seem to find the additional text in the variable d1$long 我尝试了以下操作,但似乎无法在变量d1 $ long中找到其他文本
d1 %>%
ggvis(x = ~Time, y=~Conc, key := ~long) %>%
layer_points(size.hover:=200) %>%
layer_paths(~x,~y,data=d2) %>%
add_tooltip(function(d1){
if (!is.null(d1$Time)) paste0(as.character(d1$long),"Time: ", as.character(round(d1$Time)), " minutes post-dose")
}, "hover")
The error is that the variable should be passed in the layer_points 错误是该变量应在layer_points中传递
d1 %>%
ggvis(x = ~Time, y=~Conc) %>%
layer_points(size.hover:=200, key := ~long) %>%
layer_paths(~x,~y,data=d2) %>%
add_tooltip(function(d1){
if (!is.null(d1$Time)) paste0(as.character(d1$long),"Time: ", as.character(round(d1$Time)), " minutes post-dose")
}, "hover")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.