r - 如何使用 timevis 更改时间线可视化中点的颜色?
问题描述
我正在尝试生成单个时间线的精简视图,以便我可以将其中的许多内容放在一个页面上。为了最大化没有标签的内容交付(允许推送更多点),我想在点上使用颜色编码来指示事件类型。我将样式列添加到我的数据框中,但它影响的只是标签。如何影响点本身的颜色
我调查了生成的 HTML,发现样式被附加到包含点和文本的元素的定义中,但似乎文本有它自己的样式:
<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)
如何影响每点的颜色?
解决方案
得到这个工作。样式段仅影响文本,但如果您添加一个 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)
}
推荐阅读
- javascript - JavaScript 按钮不再适用于移动设备
- google-bigquery - 跨多个表的 BigQuery DML COUNT()
- python - 有什么方法可以将 PyTorch 中可用的预训练模型下载到特定路径?
- python - sklearn sgd分类器的多输出预测?
- ssl - 在 LispWorks 中使用 easy-ssl-acceptor
- vuejs2 - 通过 nginx 与 vue/node 到 rack/thin 的 CORS 问题
- dll-injection - DLL_PROCESS_DETACH 未调用 C++
- javascript - 数据类型 JS 的 Rails 4 远程请求回调问题
- excel - 带有 $ 的内置字符串函数
- phpmailer - 处理服务器上的 List-Unsubscribe 回调