[英]R Plotly: How to change the color of the outer border?
我正在创建一个.html格式的绘图。 该情节具有黑色背景,我想知道如何将白色边框更改为黑色?
我注意到,如果定义图的尺寸(自动缩放设置为FALSE),则外面会有很多空白。
非常感谢你。
抱歉,没有发布示例,这是我第一次发布。
这是一个简单的示例:
labels = paste((data/sum(data))*100,"%")
values = c(53, 43, 77, 33)
p1 = plot_ly(labels=labels,
values=values,
type="pie",
hoverinfo = "label+percent",
showlegend = FALSE,
sort = FALSE
)
p1 = layout(p1,
paper_bgcolor="rgb(31,31,31)",
plot_bgcolor="rgb(31,31,31)",
legend = list(font = list(color = "white"),
bgcolor = "transparent"),
autosize = T,
xaxis = list(
color = "transparent"
),
yaxis = list(
color = "transparent"
)
)
p1
这是剧情的屏幕截图。 如您所见,情节周围有一个细的白色边框。
听起来好像您想要htmlwidget大小调整策略中的其他默认值。 尝试这样的事情:
p1$sizingPolicy$padding <- 0
我认为这是一个错误。 当我检查创建的html时,它显示以下内容:
<body style="margin: 5px; padding: 0px; overflow: hidden; width: 100%; height: 100%; background-color: white;">
<div id="htmlwidget_container" style="position: absolute; top: 5px; right: 5px; bottom: 5px; left: 5px;">
<div id="htmlwidget-3128" class="plotly html-widget html-widget-static-bound js-plotly-plot" style="width: 100%; height: 100%;">
<div class="plot-container plotly"><div class="svg-container" style="position: relative; width: 1270px; height: 403px;">
[...]
这意味着,实际的plotly容器被嵌入到具有5px的小部件容器中。
现在,如果您只想美化自己的html,请将开始标记更改为以下内容:
<body style="margin: 0px; padding: 0px; overflow: hidden; width: 100%; height: 100%; background-color: white;">
<div id="htmlwidget_container" style="position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px;">
如果您希望每个人都从中获利,请在plotlys项目页面上另外报告此错误。
除了@Nikolay的答案
如果您确实想更改某些样式,则可以将其转换为htmlwidget,然后使用如下方式:
library(plotly)
values = c(53, 43, 77, 33)
labels = paste((values/sum(values))*100,"%")
p1 = plot_ly(labels=labels,
values=values,
type="pie",
hoverinfo = "label+percent",
showlegend = FALSE,
sort = FALSE
)
style(p1,'#htmlwidget_container{
position: absolute;
top: 0px; right: 0px; bottom: 0px; left: 0px;
}')
p1 = layout(p1,
paper_bgcolor="rgb(31,31,31)",
plot_bgcolor="rgb(31,31,31)",
legend = list(font = list(color = "white"),
bgcolor = "transparent"),
autosize = T,
xaxis = list(
color = "transparent"
),
yaxis = list(
color = "transparent"
)
)
library(htmltools)
library(htmlwidgets)
p2=as.widget(p1)
appendContent(p2,tags$head(tags$style('
#htmlwidget_container{
position: absolute !important;
top: 0px !important;
right: 0px !important;
bottom: 0px !important;
left: 0px !important;
}')))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.