I want to knit an .Rmd document to PDF, and the document contains a code snippet where I use plotly
to build a "scatterpolar" plot of two groups from a dataset, which looks like this:
category | group1 | group2
----------|--------|-------
category1 | 25.2 | 53.8
category2 | 14.6 | 34.1
category3 | 35.7 | 35.5
... | ... | ...
Because of the warning of "less than 3 observations", the execution is halted when I try to knit it to PDF, no matter the suppressWarnings
around the code block or warning=FALSE
in the chunk options.
Code:
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)
))
How can I fix this?