如何使用ggplotly更改图形位置 [英] How to change the position of plotly figures using ggplotly

查看:100
本文介绍了如何使用ggplotly更改图形位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ggplotly删除图例标题,但未成功.我敢肯定有一个简单的解决方法,但是我找不到它的文档-使用ggplot删除图例标题(或更改位置)无法正常工作.参见例如:

I am trying to remove the legend title using ggplotly without success. I'm sure there is an easy fix, but I cannot find the documentation for it - and removing the legend title (or changing the positioning) using ggplot fails to work. See e.g.:

# Creating the ggplot:
a <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = T), 
y = mpg,fill = interaction(cyl, carb, lex.order = T))) + 
      geom_boxplot() + theme(legend.title=element_blank())
    a # No Legend Title
    # plotly puts back the legend title
    ggplotly(a)

任何想法如何更改/删除图形标题?应该使用ggplotly还是ggplot完成?

Any ideas how to change / remove the title of the graph? Should it be done using ggplotly or ggplot?

推荐答案

您可以使用labs函数:

a <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = T), 
y = mpg,fill = interaction(cyl, carb, lex.order = T))) + 
      geom_boxplot()
# update the legend
a <- a + labs(fill= "New Legend")
a
# to remove the label and update the axis texts use:
a <- a+labs(fill= "",x="Cyc/Carb",y="Miles/(US) gallon")
ggplotly(a)

这篇关于如何使用ggplotly更改图形位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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