请注意,您的图形是不是此刻的给予代码完全可重复的,所以让我知道,如果我做了不必要的假设。
TLDR:如果您喜欢问题中描述的所有更改,请查看底部。
我建议不要使用tickangle
,因为它会把事情搞砸。尝试以下操作。请注意,使用insidetextfont
和tickfont
作为yaxis
。
library(plotly)
x = c('100-200','200-400', '400-600','600-800','800- 1000')
y = c(12261,29637,17469,11233,17043)
plot_ly(
x = x, y = y, type = "bar", text = y, textposition = 'auto',
insidetextfont = list(color = 'white')
) %>% layout(
xaxis = list(title = "Length of exon"),
yaxis = list(title = "Number of genes", tickfont = list(size = 15))
)
如果你想使标签躺在酒吧外,然后用textposition = 'outside'
代替textposition = 'auto'
,并摆脱insidetextfont
默认黑色的。这可能最终会弄乱y轴的范围,您需要手动定义可能很麻烦的范围。
plot_ly(
x = x, y = y, type = "bar", text = y, textposition = 'outside'
) %>% layout(
xaxis = list(title = "Length of exon"),
yaxis = list(
title = "Number of genes", tickfont = list(size = 15),
range = c(0, max(y) + 2000)
)
)
这给了我们。
我不推荐tickangle
,但是如果必须的话,请使用margin
在layout
。
plot_ly(
x = x, y = y, type = "bar", text = y, textposition = 'outside'
) %>% layout(
xaxis = list(title = "Length of exon", tickangle = 15),
yaxis = list(
title = "Number of genes", tickfont = list(size = 15),
range = c(0, max(y) + 2000)
), margin = list(b=100)
)
希望这有助于。
谢谢Marco!工作得很好:) – Behmah
很高兴知道,但我怎么接受呢? – Behmah
我知道了,别担心 – Behmah