Plotly R实现多子图独立标题及横向条形图复刻问题
Plotly R: 复刻堆叠子图式横向条形图的问题
我正在尝试用R语言的Plotly库复刻一个堆叠子图样式的横向条形图(原效果是用Python实现的),目前已经接近目标,但还存在几个棘手的问题:
- 只有第一个子图能显示标题,其余子图的独立标题都不显示;
- 子图的标题没法左对齐;
- 条形图内的数值文本没有放在条形右侧内部,反而居中在条形的末端位置;
- 首尾两个条形的厚度明显比其他条形要大。
以下是我目前的实现代码:
library(plotly) # preparing bogus data d <- data.frame(question = paste0("Question ", 1:10), value = seq(20, 1, -2)) # setting up a list to store the plots ls_p <- NULL # Create one plot (subplot) for each categories in my data for(i in 1:nrow(d)){ ls_p[[i]] <- plot_ly(d[i,], x=~value, y=~question) |> add_bars(orientation='h') |> add_text(x=~value, y=~question, text=~value) |> layout(title = list(text=d$question[i], xanchor = "left", align = "left"), showlegend=F, grid=list(showgrid=F), xaxis=list(range=c(0,max(d$value)), showticklabels =F), yaxis=list(showticklabels = F) ) } # regroup all the subplots together subplot(ls_p, nrows= nrow(d), shareX = T, which_layout = 1, titleX = F, titleY = F)
想请教各位:这种样式的图表能不能用Plotly R实现?还是说只有Plotly Python支持这个效果?
内容的提问来源于stack exchange,提问作者Bastien
相关产品推荐
相关产品推荐

