【问题标题】:How to change the position of plotly figures using ggplotly如何使用 ggplotly 更改绘图图形的位置
【发布时间】:2015-12-28 12:45:26
【问题描述】:

我正在尝试使用 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 来完成?

【问题讨论】:

    标签: r ggplot2 plotly


    【解决方案1】:

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

    【讨论】:

    • 工作谢谢!我有一个填充和颜色调用,它们都应该设置为 "": labs(color = "", fill = "")
    猜你喜欢
    • 2021-11-27
    • 2020-10-30
    • 2021-10-23
    • 1970-01-01
    • 2018-11-30
    • 2022-01-02
    • 2018-09-10
    • 2012-11-17
    • 2020-05-14
    相关资源
    最近更新 更多