【发布时间】:2020-04-28 16:05:04
【问题描述】:
我想创建一个函数,它接受一些输入,并根据这些输入返回一个类似于下图所示的绘图对象:
两半在表盘位置和颜色上是镜像的,但中间的文字和标签不同。我看过一些例子,但它们并没有完全涵盖我需要的内容:
- 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
示例代码
首先使用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)
我想不出办法:
- 有一个连续的颜色范围,而不是我现在的阶跃变化
- 将
current_value的红色条改为箭头
感谢任何帮助。
【问题讨论】:
标签: r ggplot2 plotly gauge donut-chart