首页 > 解决方案 > 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

标签: rplotly

解决方案


推荐阅读