【问题标题】:How to know if a plot is already been called in R如何知道是否已经在 R 中调用了绘图
【发布时间】:2022-06-16 20:23:38
【问题描述】:

尝试使用 plotly 绘制图表时出现此错误: plot.new has not been called yet 这是我绘制图表的方式:

Age <-c(69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183)
Pertubation <- c(0.002967936,-0.794788368,-1.561544673,-2.938300977,-2.956057282,-3.724813586,-3.84656989,-4.000326195,-3.491082499,-3.705838803,-3.008595108,-3.439351412,-2.518107716,-2.108864021,-1.892620325,-2.175376629,-2.547132934,-2.694889238,-3.985645543,-2.702401847,-3.203158151,-3.238914456,-2.60867076,-2.564427064,-3.254183369,-1.973939673,-0.731695977,-0.625452282,-0.966208586,-0.811964891,-0.018721195,0.320522501,-0.227233804,-0.046990108,-0.820746412,-0.846502717,1.067740979,1.470984675,1.00222837,0.448472066,1.139715762,1.275959457,0.989203153,0.904446848,0.607690544,0.20693424,1.084177935,1.114421631,0.625665327,0.292909022,-0.833847282,-2.208603586,-3.397359891,-4.339116195,-4.950872499,-5.518628804,-6.992385108,-7.023141413,-8.193897717,-8.580654021,-9.428410326,-10.92316663,-11.37392293,-12.21167924,-12.77643554,-13.14219185,-13.67394815,-14.19370446,-14.16046076,-15.29121706,-16.06197337,-16.11472967,-16.29348598,-17.62424228,-17.79699859,-19.42675489,-19.6625112,-20.3642675,-21.4460238,-22.05378011,-23.87553641,-24.06129272,-25.00604902,-25.80180533,-26.77656163,-27.40431793,-28.86407424,-29.45483054,-29.37758685,-30.48534315,-30.07209946,-29.86985576,-29.82561207,-30.46936837,-30.56412467,-30.24788098,-29.40463728,-29.76939359,-29.11314989,-29.0989062,-29.2466625,-29.1654188,-29.28217511,-29.11493141,-28.44568772,-28.65344402,-28.43520033,-28.71795663,-29.06871293,-29.66546924,-28.39422554,-29.68398185,-29.73973815,-29.34349446,-29.45325076)
temp <- cbind(Age, Pertubation)

Pertubation_graph <- plot_ly(data.frame(temp), x = ~Age, y = ~res,
     cex.main = 1.5, cex.lab = 1.2, axes = F) %>%
    layout(title = paste( "Pig ID:", i, ", Lambda =", lambda, "\nDifference between CFI and TTC"),mtext("Percentage of difference: CFI - TTC (%)", side=4, line = 3, cex = 1.2, col= "blue"), plot_bgcolor = "fffff", xaxis = list(title = 'Age (d)'),
                    yaxis = list(title = 'Amount of difference: CFI - TTC (kg)'),type = "p", pch = 10, cex = 0.5,
                    ylim = c(min(B$dif.CFI, res), max(B$dif.CFI, res)), cex.main = 1.5, cex.lab = 1.2, axes = F)
Pertubation_graph <- Pertubation_graph %>%  layout(axis(1, at= seq(dif$eval_day[1],dif$eval_day[length(dif$eval_day)], by = 5), cex.axis = 1.1),
              axis(2, at=, cex.axis = 1.1),
              axis(4, at=, cex.axis = 1.1, col.axis = "blue", col = "blue"),
              abline(crit1,0, col = "red", lty = 2) ,
              abline(0,0, col = "red"))

saveWidget(ggplotly(Pertubation_graph), file=paste0("C:/Users/Kevin Le/PycharmProjects/Pig Data Black Box/Graphs/Step3_graphs/", idc, ".", ID[idc], ".html"))

我正在使用 plotly 库并将其保存为 HTML 格式。错误发生在这个断点:axis(1, at= seq(dif$eval_day[1],dif$eval_day[length(dif$eval_day)], by = 5), cex.axis = 1.1)。我做了一些研究,似乎从未调用过该情节。然而,这对我来说似乎很奇怪,因为我已经使用 plot_ly 将其称为 Pertubation_graph

我希望任何人都可以帮助我解决这个问题。 我在代码部分的数据集不起作用的情况下,这里是the data file

【问题讨论】:

  • 试试dev.list()?

标签: r plot graph plotly


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-23
  • 1970-01-01
  • 2020-02-06
  • 1970-01-01
  • 2020-04-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多