ggplot和ggplotly之间的图例位置有何不同? [英] Difference in legend position between ggplot and ggplotly?

查看:183
本文介绍了ggplot和ggplotly之间的图例位置有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现ggplot和ggplotly中的同一图表之间有一个有趣而奇怪的区别

I find out an interesting and strange difference between the same chart in ggplot and ggplotly

income_gap_chart <- ggplot(income_gap, aes(x = Country, y = Percent, fill = Income)) + 
geom_bar(position = "dodge", stat = "identity") +
scale_fill_brewer(palette = "Set1") +
coord_flip() +
theme(axis.title.y = element_blank()) +
scale_y_continuous(limits = c(0, 100)) +
theme_tufte() +
theme(axis.title.y = element_blank()) +
theme(legend.position = "bottom")

对于ggplot来说,它看起来很完美,底部带有图例标题

For ggplot it looks perfect with a legend title at the bottom

但是当我用ggpotly()包装它时,图例开始表现不同

But when I wrap this with ggpotly(), the legend starts to behave differently

我的问题-我想要第一个图表格式为ggplotly,但无法解决此问题,底部的图例不起作用.想法?

My problem - I want the first chart in ggplotly format, but cannot fix this issue and legend at the bottom does not work. Ideas?

谢谢!

推荐答案

在某些R专家的帮助下,解决速度非常快.

Resolved pretty fast with the help of some R experts.

添加了此

ggplotly(income_gap_chart) %>% layout(legend = list(orientation = "h", x = 0.4, y = -0.2))

结果:

谢谢!

这篇关于ggplot和ggplotly之间的图例位置有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆