我怎样才能使图表标题跨越多行并在情节中成为 left-justified?
How can I make a chart title go over multiple lines and be left-justified in plotly?
我正在 plotly 中创建一个 3D 散点图,并希望有一个几句话长的标题(为了描述图形),标题 left-justified,不干扰图形本身, 并且没有被绘图区域切断。
下面的代码在 left-justified 标题上合并了一个 Whosebug 答案,但是当你有一个需要超过 3-4 行的长标题时它没有帮助。
使用 \n 使标题的文本转到第二行,但它仍然被绘图区域截断并且不会 left-justify。
library(plotly)
metric1 <- c(116,230,120,200,210,188,130,99,101,120)
metric2 <- c(79,109,120,95,130,98,118,130,140,88)
metric3 <- c(30,28,42,22,6,2,17,43,20,28)
class <- c(3,4,2,1,1,4,4,3,2,3)
df <- data.frame(metric1,metric2,metric3,class)
my_colors=c("red", "blue", "green", "#000000")[df$class]
p <- plot_ly(df,
x = ~metric1,
y = ~metric2,
z = ~metric3, text = class, type = "scatter3d",
mode = "markers", marker = list(color = my_colors)) %>%
add_annotations(
x=0, y=1.15,
text="Figure: The title of the figure will explain what information can be gleaned from the figure. Then the next sentence, which is still in this title, will elaborate on implications from the results. I want to be able to extend this as needed.",
font=list(size=17)
) %>%
layout(title = FALSE,
scene = list(xaxis = list(title = 'metric 1', range = c(0,300)),
yaxis = list(title = 'metric 2', range = c(0,150)),
zaxis = list(title = 'metric 3', range = c(0,100))), showlegend = FALSE)
p
我得到的输出只显示标题的结尾并将其截断:
感谢您的帮助。
我想在 align = "left"
和 /n
的帮助下会给你想要的东西:
metric1 <- c(116,230,120,200,210,188,130,99,101,120)
metric2 <- c(79,109,120,95,130,98,118,130,140,88)
metric3 <- c(30,28,42,22,6,2,17,43,20,28)
class <- c(3,4,2,1,1,4,4,3,2,3)
df <- data.frame(metric1,metric2,metric3,class)
my_colors=c("red", "blue", "green", "#000000")[df$class]
p <- plot_ly(df,
x = ~metric1,
y = ~metric2,
z = ~metric3, text = class, type = "scatter3d",
mode = "markers", marker = list(color = my_colors)) %>%
add_annotations(
x=0.4, y=0.9,
align = "left",
# text="Figure: The title of the figure will explain what information can be gleaned from the figure. Then the next sentence, which is still in this title, will elaborate on implications from the results. I want to be able to extend this as needed.",
text=paste("Figure: The title of the figure will explain what information can be gleaned from the figure", "Then the next sentence, which is still in this title", "I want to be able to extend this as needed.", sep="\n") ,
font=list(size=17)
) %>%
layout(title = FALSE,
scene = list(xaxis = list(title = 'metric 1', range = c(0,300)),
yaxis = list(title = 'metric 2', range = c(0,150)),
zaxis = list(title = 'metric 3', range = c(0,100))), showlegend = FALSE)
p
我正在 plotly 中创建一个 3D 散点图,并希望有一个几句话长的标题(为了描述图形),标题 left-justified,不干扰图形本身, 并且没有被绘图区域切断。
下面的代码在 left-justified 标题上合并了一个 Whosebug 答案,但是当你有一个需要超过 3-4 行的长标题时它没有帮助。
使用 \n 使标题的文本转到第二行,但它仍然被绘图区域截断并且不会 left-justify。
library(plotly)
metric1 <- c(116,230,120,200,210,188,130,99,101,120)
metric2 <- c(79,109,120,95,130,98,118,130,140,88)
metric3 <- c(30,28,42,22,6,2,17,43,20,28)
class <- c(3,4,2,1,1,4,4,3,2,3)
df <- data.frame(metric1,metric2,metric3,class)
my_colors=c("red", "blue", "green", "#000000")[df$class]
p <- plot_ly(df,
x = ~metric1,
y = ~metric2,
z = ~metric3, text = class, type = "scatter3d",
mode = "markers", marker = list(color = my_colors)) %>%
add_annotations(
x=0, y=1.15,
text="Figure: The title of the figure will explain what information can be gleaned from the figure. Then the next sentence, which is still in this title, will elaborate on implications from the results. I want to be able to extend this as needed.",
font=list(size=17)
) %>%
layout(title = FALSE,
scene = list(xaxis = list(title = 'metric 1', range = c(0,300)),
yaxis = list(title = 'metric 2', range = c(0,150)),
zaxis = list(title = 'metric 3', range = c(0,100))), showlegend = FALSE)
p
我得到的输出只显示标题的结尾并将其截断:
感谢您的帮助。
我想在 align = "left"
和 /n
的帮助下会给你想要的东西:
metric1 <- c(116,230,120,200,210,188,130,99,101,120)
metric2 <- c(79,109,120,95,130,98,118,130,140,88)
metric3 <- c(30,28,42,22,6,2,17,43,20,28)
class <- c(3,4,2,1,1,4,4,3,2,3)
df <- data.frame(metric1,metric2,metric3,class)
my_colors=c("red", "blue", "green", "#000000")[df$class]
p <- plot_ly(df,
x = ~metric1,
y = ~metric2,
z = ~metric3, text = class, type = "scatter3d",
mode = "markers", marker = list(color = my_colors)) %>%
add_annotations(
x=0.4, y=0.9,
align = "left",
# text="Figure: The title of the figure will explain what information can be gleaned from the figure. Then the next sentence, which is still in this title, will elaborate on implications from the results. I want to be able to extend this as needed.",
text=paste("Figure: The title of the figure will explain what information can be gleaned from the figure", "Then the next sentence, which is still in this title", "I want to be able to extend this as needed.", sep="\n") ,
font=list(size=17)
) %>%
layout(title = FALSE,
scene = list(xaxis = list(title = 'metric 1', range = c(0,300)),
yaxis = list(title = 'metric 2', range = c(0,150)),
zaxis = list(title = 'metric 3', range = c(0,100))), showlegend = FALSE)
p