R中函数plot_ly的相同代码在项目和RGui中给出不同的结果:布局错误,未使用的参数 [英] same code for function plot_ly in R gives different results in a project and in RGui: Error in Layout, unused arguments

查看:142
本文介绍了R中函数plot_ly的相同代码在项目和RGui中给出不同的结果:布局错误,未使用的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows 10 R3.4.0的RStudio中的项目中启动一个简单功能.

#' TestPlotly
#' @export
#' @importFrom plotly plot_ly
#' @importFrom graphics layout
#' @importFrom magrittr "%>%"

TestPlotly=function()
{

  plot_ly(x = 1:10, y = 1:10,type="scatter",mode="lines") %>%
    layout(
      xaxis = list(title="tr"),
      yaxis = list(title="ts")
    )

}

我得到:

 Error in layout(., xaxis = list(title = "tr"), yaxis = list(title = "ts")) : 
  unused arguments (xaxis = list(title = "tr"), yaxis = list(title = "ts")) 
  9.
  function_list[[k]](value) 
  8.
  withVisible(function_list[[k]](value)) 
  7.
  freduce(value, `_function_list`) 
  6.
  `_fseq`(`_lhs`) 
  5.
  eval(quote(`_fseq`(`_lhs`)), env, env) 
  4.
  eval(quote(`_fseq`(`_lhs`)), env, env) 
  3.
  withVisible(eval(quote(`_fseq`(`_lhs`)), env, env)) 
  2.
  plot_ly(x = 1:10, y = 1:10, type = "scatter", mode = "lines") %>% 
      layout(xaxis = list(title = "tr"), yaxis = list(title = "ts")) at             TestPlotly.R#11
  1.
  TestPlotly::TestPlotly()

但是当我在RGui下启动时:

library(plotly)
plot_ly(x = 1:10, y = 1:10,type="scatter",mode="lines") %>%
layout(
  xaxis = list(title="tr"),
  yaxis = list(title="ts")
)

一切正常

注意:这次我在包装下得到了不同的结果,即在该处没有图形 总而言之,在我上一次尝试的地方,我得到的图形中没有标题的轴.这就是为什么我这次问类似的问题 问题是: R密谋plot_ly函数:当我在项目内部调用plotly时,轴标题不会出现

解决方案

我在plotly论坛上亲自从Carson Sievert得到了答案: 我已经通过用plotly :: layout()替换layout()解决了我的问题 当某些东西可以在Rgui上工作但不在软件包中时,可能是解决方案. 我认为让我感到困惑的是,我使用的是图形的布局,而不是使用plotly的布局,因为当我在google上查看时,我发现的唯一布局就是图形的布局.

I'm launching a simple function inside a project in RStudio for R3.4.0 for Windows 10.

#' TestPlotly
#' @export
#' @importFrom plotly plot_ly
#' @importFrom graphics layout
#' @importFrom magrittr "%>%"

TestPlotly=function()
{

  plot_ly(x = 1:10, y = 1:10,type="scatter",mode="lines") %>%
    layout(
      xaxis = list(title="tr"),
      yaxis = list(title="ts")
    )

}

I get:

 Error in layout(., xaxis = list(title = "tr"), yaxis = list(title = "ts")) : 
  unused arguments (xaxis = list(title = "tr"), yaxis = list(title = "ts")) 
  9.
  function_list[[k]](value) 
  8.
  withVisible(function_list[[k]](value)) 
  7.
  freduce(value, `_function_list`) 
  6.
  `_fseq`(`_lhs`) 
  5.
  eval(quote(`_fseq`(`_lhs`)), env, env) 
  4.
  eval(quote(`_fseq`(`_lhs`)), env, env) 
  3.
  withVisible(eval(quote(`_fseq`(`_lhs`)), env, env)) 
  2.
  plot_ly(x = 1:10, y = 1:10, type = "scatter", mode = "lines") %>% 
      layout(xaxis = list(title = "tr"), yaxis = list(title = "ts")) at             TestPlotly.R#11
  1.
  TestPlotly::TestPlotly()

But when I launch under RGui:

library(plotly)
plot_ly(x = 1:10, y = 1:10,type="scatter",mode="lines") %>%
layout(
  xaxis = list(title="tr"),
  yaxis = list(title="ts")
)

Everything works fine

NB: this time I get a different result under the package, ie no graphics at all, where as the last time I tried, I got graphics without titles on the axis. This why I am asking a similar question this time The question was: R plotly plot_ly function: axis titles don't appear when I call plotly inside a project

解决方案

I got the answer from Carson Sievert in person on the forum of plotly: I've solved my problem by replacing layout() with plotly::layout() When something works on Rgui but not in a package it might be the solution. I think that what got me was that I was using the layout from graphics instead of the layout from plotly because when I looked on google the only layout I found was the layout from graphics.

这篇关于R中函数plot_ly的相同代码在项目和RGui中给出不同的结果:布局错误,未使用的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆