从 plotly 条形图中的某些条中跳过不相关的文本
Skip irelevant text from some of bars in plotly bar chart
我创建了一个简单的 plotly 条形图,但在第一列中我得到了一个奇怪的文本,我需要将其删除。
library(plotly)
sum2<-structure(list(month = structure(c(1451606400, 1454284800, 1456790400,
1459468800, 1462060800, 1464739200, 1467331200, 1470009600, 1472688000,
1475280000), tzone = "UTC", class = c("POSIXct", "POSIXt")),
Monthly = c(14236.895, 4519.892, 55691.009, 28295.345, 23648.287,
34595.1276, 33946.393, 27909.4685, 81777.3508, 31453.393)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
fig <- plot_ly(sum2, x = ~month, y = ~Monthly, type = 'bar', text = text,
marker = list(color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5))
)
fig <- fig %>% layout( width=1800,height=600
)
fig
不确定您用 text = text
做了什么,但只需删除该行,看起来就没问题了。
plot_ly(
sum2,
x = ~ month,
y = ~ Monthly,
type = 'bar',
# text = text,
marker = list(
color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5)
)
)
发生这种情况是因为 text
指的是函数 graphics::text()
并且在不带括号的情况下调用时它只给出具有该名称的对象的报告。在控制台尝试 运行 text
(不带括号),您将看到作为标签传递给绘图的内容。
text
#> function (x, ...)
#> UseMethod("text")
#> <bytecode: 0x0000000013994f20>
#> <environment: namespace:graphics>
由 reprex package (v2.0.1)
创建于 2022-02-07
我创建了一个简单的 plotly 条形图,但在第一列中我得到了一个奇怪的文本,我需要将其删除。
library(plotly)
sum2<-structure(list(month = structure(c(1451606400, 1454284800, 1456790400,
1459468800, 1462060800, 1464739200, 1467331200, 1470009600, 1472688000,
1475280000), tzone = "UTC", class = c("POSIXct", "POSIXt")),
Monthly = c(14236.895, 4519.892, 55691.009, 28295.345, 23648.287,
34595.1276, 33946.393, 27909.4685, 81777.3508, 31453.393)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
fig <- plot_ly(sum2, x = ~month, y = ~Monthly, type = 'bar', text = text,
marker = list(color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5))
)
fig <- fig %>% layout( width=1800,height=600
)
fig
不确定您用 text = text
做了什么,但只需删除该行,看起来就没问题了。
plot_ly(
sum2,
x = ~ month,
y = ~ Monthly,
type = 'bar',
# text = text,
marker = list(
color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5)
)
)
发生这种情况是因为 text
指的是函数 graphics::text()
并且在不带括号的情况下调用时它只给出具有该名称的对象的报告。在控制台尝试 运行 text
(不带括号),您将看到作为标签传递给绘图的内容。
text
#> function (x, ...)
#> UseMethod("text")
#> <bytecode: 0x0000000013994f20>
#> <environment: namespace:graphics>
由 reprex package (v2.0.1)
创建于 2022-02-07