简体   繁体   中英

How to change the position of plotly figures using ggplotly

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 eg:

# 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)

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

You can use the labs function:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM