r - Rangeslider() 增加柱状图中文本和条形之间的距离
问题描述
为什么文本和条形之间的距离如此之大。我想要文字就在酒吧外面。是添加后引起的rangeSlider()
。
d<-data.frame(structure(list(Country = c("Austria", "Belgium", "Bulgaria",
"Croatia", "Cyprus", "Czechia", "Denmark", "Estonia", "Finland",
"France", "Germany", "Greece", "Hungary", "Iceland", "Ireland",
"Italy", "Latvia", "Liechtenstein", "Lithuania", "Luxembourg",
"Malta", "Netherlands", "Norway", "Poland", "Portugal", "Romania",
"Slovakia", "Slovenia", "Spain", "Sweden"), `Uptake first dose (%)` = c(21.1,
20.9, 8.2, 14.7, 18.7, 15.8, 18.9, 24.1, 25.8, 20.5, 19.1, 16.2,
35.9, 21.6, 20.4, 18.1, 7.8, 14, 20.6, 19.7, 34.4, 21.6, 19.9,
19, 18.5, 14.6, 19.6, 19.3, 21.7, 18.3)), class = "data.frame", row.names = c(NA,
-30L)))
colnames(d)[2]<-"Uptake first dose (%)"
fig1 <- plot_ly(d, y = ~`Uptake first dose (%)`, x = ~Country,
type = 'bar',
hovertemplate = paste('%{x}', '<br>Uptake first dose (%): %{y}<br><extra></extra>'),
text = paste(d$`Uptake first dose (%)`, '%'),
textposition = 'outside',
textangle=90,
#change color
textfont = list(color = "black"),#texttemplate = '%{y:.2s}', textposition = 'outside',
marker = list(color = '#63bb47')
)
fig1 <- fig1 %>% layout(font = list(color = '#a2a2a2'),
uniformtext=list(minsize=10, mode='show'),
xaxis = list(rangeslider = list(),fixedrange = TRUE,title="",showgrid = FALSE,tickangle=90, showline = FALSE, showticklabels = TRUE, domain= c(0, 0.85)),
yaxis = list(rangeslider = list(),fixedrange = TRUE,title="",zeroline = FALSE,range = c(0,(max(d$`Uptake first dose (%)`)+4)), showline = FALSE, showticklabels = FALSE, showgrid = FALSE)) %>%
config(modeBarButtonsToRemove = c('toImage',"zoom2d","toggleSpikelines","hoverClosestCartesian","hoverCompareCartesian","drawline","autoScale2d" ,"resetScale2d","zoomIn2d","zoomOut2d","pan2d",'select2d','lasso2d'))%>%
config(displaylogo = FALSE)
fig1
解决方案
推荐阅读
- bash - 如何将多个 Ansible 变量添加到 csv 文件的单行中?
- dll - 有没有办法让我的 .NET Blazor WASM 应用程序不被大多数防火墙阻止?
- vue.js - 如何解决测试用例 vue 测试工具中的工具提示警告?
- html - 如何将微型 mce 图像源从远程 Web 服务器更改为本地服务器目录
- java - 使用 Micornaut 和 swagger 的 Codegen 错误
- node.js - 通过节点firebase-admin发送push时,push不来IOS的现象
- python - 在heroku中通过pipenv从git安装
- python - Python - CSV 文件中的列包含多个分隔符和结果
- python - 是否有与 Python 的 itertools.combinations 等效的 Go?
- mysql - 在 laravel 中更新时如何优化查询原始?