0

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.

DasherS
  • 1
  • 1
  • Please read https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610. Your chances of getting an answer are greater if you include a sample of your data and a copy of the code you used, not just the error message. – GuedesBF May 18 '21 at 18:18
  • Thank you so much for guiding me. – DasherS May 18 '21 at 19:57
  • Please always post the actual code for your data instead of formated tables. If you don't have the code, and have only the object itself, you can paste the output of `dput(DataGlobal)` or, if it is too big, `dput(your_subset_of_the_data)` – GuedesBF May 18 '21 at 20:00
  • 1
    I would take a look at r-markdown. You should be able to create a document with the plots of interest and then knit into html. – Dave2e May 18 '21 at 22:25

0 Answers0