'how to make calculation for y value in tooltip in sparkline in r
I am trying to show ranking in line and increase in number means a decrease in rank. That's why to visualize this relation I multiple rank values with minus 1. However, in tooltip it shows up with minus sign and I can't make calculations in double curly braces. Code is below.
library(data.table)
library(sparkline)
library(tidyverse)
library(DT)
vec_line <- data.table(rank = c(3,2,6,7), cur_year=c(2001,2002,2003,2004))
line = spk_chr(-vec_line[,rank],
type="line",
chartRangeMin = min(-vec_line[,rank]),
chartRangeMax = max(-vec_line[,rank]),
xvalues = vec_line[,cur_year],
tooltipFormat= sprintf('<span style=\"color: {{color}}\">●</span> Year {{x}}: {{y}}.'),
numberDigitGroupSep = "",
width = 150,
height = 50,
lineColor = '#896B84',
fillColor = NULL,
lineWidth = 2)
datatable(data.table(graph = line),
escape = F,
options = list(fnDrawCallback = htmlwidgets::JS('function(){HTMLWidgets.staticRender();}')))%>%
spk_add_deps()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
