I'd like to create a function that takes some inputs based on which it returns a plot object similar to the one shown below:
The two halves are mirror images in terms of dial position and colors but the text in the center and the labels are different. I've seen some examples but they don't fully cover what I need:
- ggplot Donut chart
- Dial Position Gauge Chart Plotly R,
- https://www.r-graph-gallery.com/doughnut-plot.html
- Hide labels in plotly donut chart r
sample code
Attempting the top half of the plot first using plotly
:
plot_func <- function(current_value){
fig <- plot_ly(
domain = list(x = c(0, 1), y = c(0, 1)),
value = current_value,
title = list(text = "Rating"),
type = "indicator",
mode = "number+gauge",
gauge = list(
axis =list(range = list(100, 85)),
bar = list(
# color = 'white',
# line = list(width = 1),
thickness = 0
),
steps = list(
list(range = c(85,90), color = "#b20000", name = 'E'),
list(range = c(90,92.5), color = "#e09999", name = 'D'),
list(range = c(92.5, 95), color = "#ffffb2", name = 'C'),
list(range = c(95, 97.5), color = '#7fbf7f', name = 'B'),
list(range = c(97.5,100), color = "#008000", name = 'A')),
threshold = list(
line = list(color = "red", width = 4),
thickness = 0.75,
value = current_value)))
return(fig)
}
myplot <- plot_func(current_value = 99.8)
I can't figure out a way to:
- Have a continuous color range rather than the step change I have right now
- change the red bar for
current_value
to an arrow instead
Any help is appreciated.