I would like to add tick marks on a flexdashboard guage plot and then highlight a specific point where the gauge bar would transition from success to danger. Here is my code so far:
flexdashboard::gauge(42, min = 0, max= 100,
abbreviateDecimals = 2,
sectors = flexdashboard::gaugeSectors(success = c(0,50),
warning = c(50,75),
danger = c(75,100),
colors = c('green','yellow','red')))
Here's how it looks now
And I would like it to look something like this
Even if it doesn't look as clean as the second image it would be nice to have the tick marks on the plot and then have some way of highlighting the point at which the bar would change colors.
Recreated a similar gauge chart in Highcharter
, as I don't think this is possible with flexdashboard::gauge()
. You can play with the innerRadius
and outerRadius
of the plot bands to get them below the main gauge fill.
Code used to generate the plot:
library(highcharter)
library(dplyr)
df <- data.frame(Value = 42)
hchart(
df,
hcaes(y = Value),
name = "Value",
type = "solidgauge",
radius = 93,
dataLabels = list(
borderWidth = 0,
padding = 0,
y = -20,
style = list(
fontWeight = "bold",
fontSize = "60px")
)
) |>
hc_pane(
startAngle = -120,
endAngle = 120,
background = list(
backgroundColor = "lightgrey",
borderWidth = 0,
outerRadius = '100%',
innerRadius = '60%',
shape = "arc"
)
) |>
hc_yAxis(
title = list(
text = ""
),
min = 0,
max = 100,
minorTicks = FALSE,
tickWidth = 0,
lineWidth = 0,
offset = -15,
labels = list(
style = list(
fontSize = "1.2em",
color = "lightgrey"),
distance = 35
),
plotBands = list(
list(
from = 0,
to = 50,
color = "green"
),
list(
from = 50,
to = 75,
color = "yellow"
),
list(
from = 75,
to = 100,
color = "red"
)
)
) |>
hc_chart(style = list(fontFamily = "Source Sans Pro")) |>
hc_colors(colors = case_when(
df$Value < 51 ~ "green",
df$Value < 76 ~ "yellow",
.default = "red"
))