如何删除 R 中 plotly 项目符号图表周围的空白
How to remove the whitespace surrounding a plotly bullet chart in R
我在 R 中创建了以下子弹图
library(plotly)
fig<-plot_ly()
fig <- fig %>%
add_trace(
type = "indicator",
mode = "number+gauge+delta",
value = 35,
delta = list(reference = 100),
domain = list(x = c(0.25, 1), y = c(0.4, 0.6)),
title = list(text = "Avalue"),
gauge = list(shape = "bullet",axis = list(range = list(NULL, 100)),threshold = list(
line = list(color = "black", width= 2), thickness = 0.75,value = 55),steps = list(
list(range = c(0, 25), color = "red"),
list(range = c(25, 50), color = "blue"),
list(range = c(50, 75), color = "green"),
list(range = c(75, 100), color = "grey")),
bar = list(color = "grey")))
如何删除图表周围的空白。有什么方法可以调整图表的长度
您应该在 add_trace
中更改 domain
的值。我将 y
更改为 FALSE
并将 x
更改为不同的范围,结果如下图:
library(plotly)
fig<-plot_ly()
fig <- fig %>%
add_trace(
type = "indicator",
mode = "number+gauge+delta",
value = 35,
delta = list(reference = 100),
domain = list(x = c(0.1, 1), y = FALSE),
title = list(text = "Avalue"),
gauge = list(shape = "bullet",axis = list(range = list(NULL, 100)),threshold = list(
line = list(color = "black", width= 2), thickness = 0.75,value = 55),steps = list(
list(range = c(0, 25), color = "red"),
list(range = c(25, 50), color = "blue"),
list(range = c(50, 75), color = "green"),
list(range = c(75, 100), color = "grey")),
bar = list(color = "grey")))
fig
输出:
如您所见,空格少了很多。
我在 R 中创建了以下子弹图
library(plotly)
fig<-plot_ly()
fig <- fig %>%
add_trace(
type = "indicator",
mode = "number+gauge+delta",
value = 35,
delta = list(reference = 100),
domain = list(x = c(0.25, 1), y = c(0.4, 0.6)),
title = list(text = "Avalue"),
gauge = list(shape = "bullet",axis = list(range = list(NULL, 100)),threshold = list(
line = list(color = "black", width= 2), thickness = 0.75,value = 55),steps = list(
list(range = c(0, 25), color = "red"),
list(range = c(25, 50), color = "blue"),
list(range = c(50, 75), color = "green"),
list(range = c(75, 100), color = "grey")),
bar = list(color = "grey")))
如何删除图表周围的空白。有什么方法可以调整图表的长度
您应该在 add_trace
中更改 domain
的值。我将 y
更改为 FALSE
并将 x
更改为不同的范围,结果如下图:
library(plotly)
fig<-plot_ly()
fig <- fig %>%
add_trace(
type = "indicator",
mode = "number+gauge+delta",
value = 35,
delta = list(reference = 100),
domain = list(x = c(0.1, 1), y = FALSE),
title = list(text = "Avalue"),
gauge = list(shape = "bullet",axis = list(range = list(NULL, 100)),threshold = list(
line = list(color = "black", width= 2), thickness = 0.75,value = 55),steps = list(
list(range = c(0, 25), color = "red"),
list(range = c(25, 50), color = "blue"),
list(range = c(50, 75), color = "green"),
list(range = c(75, 100), color = "grey")),
bar = list(color = "grey")))
fig
输出:
如您所见,空格少了很多。