[英]How to change the legend position when transfer ggplot2 to plotly using `ggplotly`?
As the code below, I constructed a plotly from a ggplot, and want to change the position of the legend. 如下面的代码,我从ggplot中构建了一个情节,并希望改变图例的位置。
df <- data.frame(n=1:10, Var1 = rnorm(10), Var2 = rnorm(10))
data_long <- melt(df, id = "n")
a <- ggplot(data_long,
aes(x = n, y = value, colour = variable, group = variable)) +
geom_line()
ggplotly(a) %>% layout(legend = list(x = 0, y = 0), yaxis = list(title = ""))
The ggplot looks like ggplot看起来像
But the plotly looks like 但情节看起来像
Part of the legend title is still on the top of the graph. 部分传奇标题仍位于图表的顶部。
You can use legend.position argument: 您可以使用legend.position参数:
a <- ggplot(data_long,
aes(x = n, y = value, colour = variable, group = variable)) +
geom_line() +
theme(legend.justification=c(0,0), legend.position=c(0,0))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.