拨号位置仪表图表Plotly R.

时间:2017-10-20 16:52:50

标签: r svg plotly

这个问题似乎已经以某种方式被问过几次,但我似乎找不到正确的答案。我正试图在plotly仪表图表上移动中心刻度盘。我正在使用已提供的演示(https://plot.ly/r/gauge-charts/),我也在使用此帖子中的指导(How to rotate the dial in a gauge chart? Using python plotly) - 尽管它是python而不是r

我对SVG的经验绝对没有 - 因为我相信你能说出来。任何帮助将不胜感激。

h = 0.24
k = 0.5
r = 0.15

my_raw_value = 100
theta = my_raw_value * 180/300
theta = theta * pi / 180
x = h + r*cos(theta)
y = k + r*sin(theta)
path = paste0('M 0.235 0.5 L ' ,str(x) , '', str(y),' L 0.245 0.5 Z')

base_plot <- plot_ly(
  type = "pie",
  values = c(40, 10, 10, 10, 10, 10, 10),
  labels = c("-", "0", "20", "40", "60", "80", "100"),
  rotation = 108,
  direction = "clockwise",
  hole = 0.4,
  textinfo = "label",
  textposition = "outside",
  hoverinfo = "none",
  domain = list(x = c(0, 0.48), y = c(0, 1)),
  marker = list(colors = c('rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)')),
  showlegend = FALSE
)

base_plot <- add_trace(
  base_plot,
  type = "pie",
  values = c(50, 10, 10, 10, 10, 10),
  labels = c("Error Log Level Meter", "Debug", "Info", "Warn", "Error", "Fatal"),
  rotation = 90,
  direction = "clockwise",
  hole = 0.3,
  textinfo = "label",
  textposition = "inside",
  hoverinfo = "none",
  domain = list(x = c(0, 0.48), y = c(0, 1)),
  marker = list(colors = c('rgb(255, 255, 255)', 'rgb(232,226,202)', 'rgb(226,210,172)', 'rgb(223,189,139)', 'rgb(223,162,103)', 'rgb(226,126,64)')),
  showlegend= FALSE
)

a <- list(
  showticklabels = FALSE,
  autotick = FALSE,
  showgrid = FALSE,
  zeroline = FALSE)

b <- list(
  xref = 'paper',
  yref = 'paper',
  x = 0.23,
  y = 0.45,
  showarrow = FALSE,
  text = '50')

base_chart <- layout(
  base_plot,
  shapes = list(
    list(
      type = 'path',
      path = path,
      xref = 'paper',
      yref = 'paper',
      fillcolor = 'rgba(44, 160, 101, 0.5)'
    )
  ),
  xaxis = a,
  yaxis = a,
  annotations = b
)

为什么这条路不会起作用?我希望这不是一个明显的答案,我无知地忽略了。

1 个答案:

答案 0 :(得分:1)

path字符串的定义出错 这是正确的sintax:

path = paste('M 0.235 0.5 L' , x, y, 'L 0.245 0.5 Z')

enter image description here