我想将.Rmd文档编织为PDF,并且该文档包含一个代码段,其中我使用plotly
从数据集中构建两组的“散极”图,如下所示:>
category | group1 | group2
----------|--------|-------
category1 | 25.2 | 53.8
category2 | 14.6 | 34.1
category3 | 35.7 | 35.5
... | ... | ...
由于警告“少于3个观察值”,无论代码块周围的suppressWarnings
还是块选项中的warning=FALSE
,当我尝试将其编织为PDF时,执行都会暂停
代码:
library(plotly)
suppressWarnings(plot_ly(
data[data$category != "category5",],
type = "scatterpolar",
mode = "lines+markers"
) %>% add_trace(
r = ~group1,
theta = ~category,
color = ~"Group 1",
line = list(color="#000088",width=2),
marker = list(color="#000088",width=2)
) %>% add_trace(
r = ~group2,
theta = ~category,
color = ~"Group 2",
line = list(color="#FF0000", width=2),
marker = list(color="#FF0000", width=2)
) %>% layout(
title="Title",
annotations=list(x=1, y=-.1, text="Source", showarrow=FALSE, xanchor="right"),
legend=list(x=.9),
margin=list(t=100, b=50, r=-100)
))
我该如何解决?
答案 0 :(得分:0)
我现在知道了:colors
函数中的plot_ly
属性可以解决问题。
library(plotly)
plot_ly(
data[data$category != "category5",],
type = "scatterpolar",
mode = "lines+markers",
colors = c("#000088","#FF0000")
) %>% add_trace(
r = ~group1,
theta = ~category,
color = ~"Group 1",
line = list(color="#000088",width=2),
marker = list(color="#000088",width=2)
) %>% add_trace(
r = ~group2,
theta = ~category,
color = ~"Group 2",
line = list(color="#FF0000", width=2),
marker = list(color="#FF0000", width=2)
) %>% layout(
title="Title",
annotations=list(x=1, y=-.1, text="Source", showarrow=FALSE, xanchor="right"),
legend=list(x=.9),
margin=list(t=100, b=50, r=-100)
)