我怎样才能把图例放在图表的顶部而不是底部呢?
library(plotly)
library(tidyr)
library(plyr)
data <- spread(Orange, Tree, circumference)
data <- rename(data, c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
fig <- plot_ly(data, x = ~age, y = ~Tree1, type = 'scatter', mode = 'lines', name = 'Tree 1')
fig <- fig %>% add_trace(y = ~Tree2, name = 'Tree 2')
fig <- fig %>% add_trace(y = ~Tree3, name = 'Tree 3')
fig <- fig %>% add_trace(y = ~Tree4, name = 'Tree 4')
fig <- fig %>% add_trace(y = ~Tree5, name = 'Tree 5')
fig <- fig %>% layout(legend = list(orientation = 'h'))
fig
1条答案
按热度按时间mf98qq941#
您可以在
layout
中指定legend
的x和y坐标,如下所示:创建于2023年3月13日,使用reprex v2.0.2