R Plotly - 设置高度时图表顶部和底部未使用的大 space
R Plotly - Large unused space on top and bottom of graph when setting height
我正在尝试创建一个在 y 轴上包含分类数据的散点图,以便可以通过向下滚动来查看数据。
为此,我将刻度类型设置为 'category' 并将其模式设置为 'linear' 并手动设置高度以允许有足够的空间显示每个标签。然而,这让我在情节的顶部和底部留下了很大的差距
这是一个例子:
testdata <- data.frame(a = sample(0:500),b = 0:500)
plot_ly(testdata,
type = 'scatter',
mode = 'markers',
x = ~a,
y = ~b,
height = 5000
) %>%
layout(
margin = list(
l = 50,
r = 50,
b = 100,
t = 1,
pad = 1
),
yaxis = list(
type = 'category',
tickmode = 'linear',
dtick = 1
)
)
Image of plot showing large white spaces on top and bottom
我试过调整填充和边距,但没有成功。设置较低的高度只会导致略小的白色 space,但不包括所有 y 标签。
理想的结果是上下白色 space 更小并且显示所有 y 轴标签。
您可以简单地设置y轴范围:
library(plotly)
testdata <- data.frame(a = sample(0:500),b = 0:500)
plot_ly(testdata,
type = 'scatter',
mode = 'markers',
x = ~a,
y = ~b,
height = 5000
) %>%
layout(
margin = list(
l = 50,
r = 50,
b = 100,
t = 1,
pad = 1
),
yaxis = list(
type = 'category',
tickmode = 'linear',
dtick = 1,
range = c(min(testdata$b)-1, max(testdata$b)+1)
)
)
我正在尝试创建一个在 y 轴上包含分类数据的散点图,以便可以通过向下滚动来查看数据。
为此,我将刻度类型设置为 'category' 并将其模式设置为 'linear' 并手动设置高度以允许有足够的空间显示每个标签。然而,这让我在情节的顶部和底部留下了很大的差距
这是一个例子:
testdata <- data.frame(a = sample(0:500),b = 0:500)
plot_ly(testdata,
type = 'scatter',
mode = 'markers',
x = ~a,
y = ~b,
height = 5000
) %>%
layout(
margin = list(
l = 50,
r = 50,
b = 100,
t = 1,
pad = 1
),
yaxis = list(
type = 'category',
tickmode = 'linear',
dtick = 1
)
)
Image of plot showing large white spaces on top and bottom
我试过调整填充和边距,但没有成功。设置较低的高度只会导致略小的白色 space,但不包括所有 y 标签。
理想的结果是上下白色 space 更小并且显示所有 y 轴标签。
您可以简单地设置y轴范围:
library(plotly)
testdata <- data.frame(a = sample(0:500),b = 0:500)
plot_ly(testdata,
type = 'scatter',
mode = 'markers',
x = ~a,
y = ~b,
height = 5000
) %>%
layout(
margin = list(
l = 50,
r = 50,
b = 100,
t = 1,
pad = 1
),
yaxis = list(
type = 'category',
tickmode = 'linear',
dtick = 1,
range = c(min(testdata$b)-1, max(testdata$b)+1)
)
)