R语言Plotly柱状图如何将底部注释设置为左对齐
R语言Plotly注释文本左对齐设置方法
直接在annotations配置列表中新增align = "left"参数即可。
Plotly的注释组件默认align属性值为center,因此你用\n拆分的多行注释会默认以锚点为中心居中排布,显式设置对齐属性为左对齐就能解决问题。
修改后完整代码
library(plotly) library(reshape2) library(dplyr) plot_ly( x = c("giraffes*", "whale**", "monkeys"), y = c(20, 14, 23), name = "SF Zoo", type = "bar" ) |> layout(annotations = list( x = 0, y =-0.131, text = "Note: * The tallest animal,Unsurprisingly, the giraffe is the world's tallest living animal by standing height. Male giraffes can measure up to 6 meters or almost 20 feet, but with a height of up to 5.2 meters or 17 feet \n Note: ** Тhe longest animal" , showarrow = FALSE, xref='paper', yref='paper', align = "left" # 配置注释文本左对齐 ) )
可选优化
当前你设置的x=0对应绘图区域的最左边缘,左对齐后文本会紧贴边缘,如果觉得视觉上太挤,可以把x值微调为0.01~0.03,给注释左侧留出少量留白。
内容的提问来源于stack exchange,提问作者silent_hunter
相关产品推荐
相关产品推荐

