如何使用ggplotly更改绘图图形的位置

How to change the position of plotly figures using ggplotly

我正在尝试使用 ggplotly 删除图例标题,但没有成功。我确定有一个简单的修复方法,但我找不到它的文档 - 使用 ggplot 删除图例标题(或更改定位)无法正常工作。参见例如:

# 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 来完成?

您可以使用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)