[英]R plotly stacked bar chart text labels not aligned to bars
我花了太长时间在 google/stack overflow 上搜索,试图找到答案,但没有成功!
本质上,我创建了一个堆积条形图,但覆盖的文本标签与正确的条形不对齐。 我试过使用text = ~value
, annotations
参数等等......但没有运气。
这是我最新版本的代码和图片示例。 我假设它一定是一个简单的解决方案,但我无法弄清楚!
t <- list(
size = 12,
color = 'black')
fig <- df4 %>% plot_ly(x = ~variable, y = ~value, type = 'bar',
name = ~Country, color = ~Country) %>%
layout(yaxis = list(title = '% of Value'),
xaxis = list(title = 'Metric'),
barmode = 'stack',
title = "Proportion of value across countries") %>%
add_text(text=~value, textposition="middle center",
showlegend = F, textfont = t)
fig
设法解决它:
fig <- df4 %>% plot_ly(x = ~variable, y = ~value, type = 'bar',
text = paste(df4$value,"%"),
textposition = "outside",
color = ~Country,
textfont = t)%>%
layout(yaxis = list(title = '% of Value'),
xaxis = list(title = 'Country'),
title = "Proportion of value across countries",
barmode = 'stack')
fig
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.