我有以下代码生成散点图,并且我想更改图例的位置,使其仍然位于图的外部,但位于中心或中间,我该怎么做?
f <- list(
family = "Courier New, monospace",
size = 18,
color = "#7f7f7f"
)
x <- list(
title = "Age of Buildings",
titlefont = f,
zeroline = FALSE,
showline = FALSE,
showticklabels = TRUE,
showgrid = TRUE
)
y <- list(
title = "Total Violations",
titlefont = f,
zeroline = FALSE,
showline = FALSE,
showticklabels = TRUE,
showgrid = TRUE
)
fig2 <- plot_ly(final, x=~agebuilding, y=~violationstotal, mode= "markers", color = ~INdexrehabless6, size = ~totalvalue)
fig2 <- fig2 %>% layout(xaxis = x, yaxis = y, legend=list(title=list(text='<b> Housing Conditions </b>'))) #chaging name legend
fig2
这是我得到的情节
对于具有垂直方向的默认图例,其位置对应于
layout(legend = list(orientation = "v", y = 1, x = 1))
如果要将其放在y方向的底部,请使用
layout(legend = list(orientation = "v", y = 0, x = 1))
如果要使其在y方向居中,请使用
layout(legend = list(orientation = "v", y = .5, x = 1))
如果是水平方向,则默认位置是
layout(legend = list(orientation = "h", y = -.1, x = 0))
并将图例放在图的左下角。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句