R 如何使用timevis更改时间轴可视化中点的颜色?
我正在尝试生成一个单一时间线的压缩视图,这样我就可以在一个页面上容纳许多时间线。为了最大化无标签的内容交付(允许推送更多点),我想在点上使用颜色编码来指示事件类型。 我将样式列添加到数据框中,但它只影响标签。如何影响点本身的颜色 我研究了生成的HTML,发现样式被附加到包含点和文本的元素定义中,但文本似乎有自己的样式:R 如何使用timevis更改时间轴可视化中点的颜色?,r,vis.js-timeline,R,Vis.js Timeline,我正在尝试生成一个单一时间线的压缩视图,这样我就可以在一个页面上容纳许多时间线。为了最大化无标签的内容交付(允许推送更多点),我想在点上使用颜色编码来指示事件类型。 我将样式列添加到数据框中,但它只影响标签。如何影响点本身的颜色 我研究了生成的HTML,发现样式被附加到包含点和文本的元素定义中,但文本似乎有自己的样式: <div class="vis-item vis-point vis-readonly" style="border-color: red; color: red; lef
<div class="vis-item vis-point vis-readonly" style="border-color: red; color: red; left: 343.741px; top: 5px;">
<div style="margin-left: 16px;" class="vis-item-content">point1</div>
<div style="top: 11px; left: 4px;" class="vis-item vis-dot vis-readonly"></div>
</div>
第一点
要复制的代码:
data = data.frame (
content = c ("point1", "point2", "point3"),
start = c ("2010-03-28", "2012-01-17", "2013-12-15"),
end = c ("2010-03-28", "2012-01-17", "2013-12-15"),
type = c ("point", "point", "point"),
style = c ("border-color: red; color: red;", "border-color: blue; color: blue", "border-color: red; color: red;"))
ui <- fluidPage(
timevisOutput("timeline")
)
server <- function (input, output, session) {
output$timeline <- renderTimevis ({
timevis (data = data, options = list(stack = FALSE))
})
}
shinyApp(ui = ui, server = server)
data=data.frame(
内容=c(“第1点”、“第2点”、“第3点”),
start=c(“2010-03-28”、“2012-01-17”、“2013-12-15”),
结束=c(“2010-03-28”、“2012-01-17”、“2013-12-15”),
类型=c(“点”、“点”、“点”),
style=c(“边框颜色:红色;颜色:红色;”,“边框颜色:蓝色;颜色:蓝色”,“边框颜色:红色;颜色:红色;”)
ui让它起作用了。样式段只影响文本,但是如果添加一个className列,就可以定义一个样式,然后可以添加一个实际控制该点的CSS。请参见下面的工作示例:
Example <- function ()
{
data = data.frame (
content = c ("point1", "point2", "point3"),
start = c ("2010-03-28", "2012-01-17", "2013-12-15"),
end = c ("2010-03-28", "2012-01-17", "2013-12-15"),
type = c ("point", "point", "point"),
style = c ("color: red;", "color: blue;", "color: red;"),
className = c ("red_point", "blue_point", "red_point"))
ui <- fluidPage(
title = "Rami is testing styles",
tags$head(
tags$style(HTML("
.red_point { border-color: red; }
.blue_point { border-color: blue; }
"))),
timevisOutput("timeline")
)
server <- function (input, output, session) {
output$timeline <- renderTimevis ({
timevis (data = data, options = list(stack = FALSE))
})
}
shinyApp(ui = ui, server = server)
}
示例