Its my first time posting on Stackoverflow. I am facing a problem in R right now. I have a LIST of plotly line charts and I am trying to save all of them in one HTML file but I am not able to. In addition I also want to save all charts in pdf too.
I have the dataset "DataGlobal" with three columns
structure(list(YQ = c(“2021Q1”,"2021Q2", "2021Q3", "2021Q4", "2022Q1", "2022Q2", "2022Q3", "2022Q4" ), series = structure(c(1L,1L,1L,1L,1L,1L,1L,1L), .Label = “Outlook”, class = “factor”), value = c(176, 168, 172, 176, 177, 178, 179, 180)), row.names = c(NA, -8L), class = “data.frame”)
YQ | series | value |
---|---|---|
2021Q1 | Outlook | 176 |
2021Q2 | Outlook | 168 |
2021Q3 | Outlook | 172 |
2021Q4 | Outlook | 176 |
2022Q1 | Outlook | 177 |
2022Q2 | Outlook | 178 |
2022Q3 | Outlook | 179 |
2022Q4 | Outlook | 180 |
and here is the code and the error I am getting:
globalplots = list()
for (i in 1:42) {
p <- ggplot(DataGlobal, aes(YQ, value, colour = series, group = series))+
geom_line(aes(linetype = series)) +
ggtitle("Variable 1") +
scale_linetype_manual(values = "solid", labels = c("Outlook")) +
scale_colour_manual(values = "red", labels = c("Outlook")) +
scale_shape_manual(values = 46, labels = c("Outlook")) +
xlab("Quarters") +
ylab("Numbers") +
theme(axis.text.x = element_text(face = "bold", color = "#993333", size = 6, angle = 45), legend.background = element_rect(fill = NULL))
p <- ggplotly(p)
globalplots[[i]] <- p
}
htmlwidgets::saveWidget(as_widget(globalplots), "index.html")
Error in shouldEval(list) :
'options' must be a fully named list, or have no names (NULL)
where globalplots is a list of plotly charts.