Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R错误:第一个参数“data”必须是数据帧或共享数据_R_Dplyr_Plotly_Data Manipulation_Interactive - Fatal编程技术网

R错误:第一个参数“data”必须是数据帧或共享数据

R错误:第一个参数“data”必须是数据帧或共享数据,r,dplyr,plotly,data-manipulation,interactive,R,Dplyr,Plotly,Data Manipulation,Interactive,我正在使用R编程语言。我在这里学习本教程: 我尝试创建自己的数据并运行相同的过程: library(plotly) library(MASS) library(dplyr) # create data x <- sample( LETTERS[1:4], 731, replace=TRUE, prob=c(0.25, 0.25, 0.25, 0.25) ) y <- rnorm(731,10,10) z <- rnorm(731,5,5) date= seq(as.Dat

我正在使用R编程语言。我在这里学习本教程:

我尝试创建自己的数据并运行相同的过程:

library(plotly)
library(MASS)
library(dplyr)


# create data

x <- sample( LETTERS[1:4], 731, replace=TRUE, prob=c(0.25, 0.25, 0.25, 0.25) )
y <- rnorm(731,10,10)
z <- rnorm(731,5,5)
date= seq(as.Date("2014/1/1"), as.Date("2016/1/1"),by="day")
    
    df <- data.frame(x,y, z, date)
df$x = as.factor(df$x)


#create plot
fig <- plot_ly(df, x = ~y, z = ~z )
fig <- fig %>%  plot_ly(df, y = ~y, color = ~x, type = "box")
fig <- fig %>%  plot_ly( data = df, type = "scatter", mode = "markers", x = ~ y, y = ~z)
fig <- fig %>% layout(
    title = "Drop down menus - Styling",
    xaxis = list(domain = c(0.1, 1)),
    yaxis = list(title = "y"),
    updatemenus = list(
        list(
            y = 0.8,
            buttons = list(
                
                list(method = "restyle",
                     args = list("line.color", "blue"),
                     label = "Blue"),
                
                list(method = "restyle",
                     args = list("line.color", "red"),
                     label = "Red")))
    )
)

fig
我试图在这个“无花果”中添加另一个情节

时间序列图 聚合=df%>% 变异(日期=as.date(日期))%>% 分组依据(月=格式(日期,“%Y-%m”))%>% 总结(平均值=平均值(y))
t_1我不确定您试图实现该页面中的哪个绘图。下面是一种实现前两种方法的方法

数据:

library(plotly)
x <- sample( LETTERS[1:4], 731, replace=TRUE, prob=c(0.25, 0.25, 0.25, 0.25) )
y <- rnorm(731,10,10)
z <- rnorm(731,5,5)
date= seq(as.Date("2014/1/1"), as.Date("2016/1/1"),by="day")

df <- data.frame(x,y, z, date)
df$x = as.factor(df$x)
library(plotly)

x感谢@Ronak Shah对您的帮助!我正在尝试将您发布的第一张图片和第二张图片合并到一个plotly对象中。我正在尝试制作一个plotly对象,您可以在其中一起查看不同类型的绘图(例如散点图、时间序列、方框图等)。这个问题与我之前发布的另一个问题有关:。你知道这样做是否可行吗?非常感谢你的帮助!第一张照片不是你想要的吗?它有散点图和二维直方图。你只需要在其中添加更多的情节。所以这是一个不同的问题,在那篇文章中处理,对吗?我认为这个问题不同于另一个问题。所以我不确定你在这个问题上寻找的是什么。两个图都有不同的轴,所以我不确定我们是否可以将它们结合起来。
# time series plot
 aggregate = df %>%
        mutate(date = as.Date(date)) %>%
        group_by(month = format(date, "%Y-%m")) %>%
        summarise( mean = mean(y))

ts_1 <- ggplot(aggregate) + geom_line(aes(x = month, y = mean, group = 1)) +  theme(axis.text.x = element_text(angle = 90)) + ggtitle("time series 1")

plot_1 = ggplotly(ts_1)

fig <- fig %>%  plot_1
library(plotly)
x <- sample( LETTERS[1:4], 731, replace=TRUE, prob=c(0.25, 0.25, 0.25, 0.25) )
y <- rnorm(731,10,10)
z <- rnorm(731,5,5)
date= seq(as.Date("2014/1/1"), as.Date("2016/1/1"),by="day")

df <- data.frame(x,y, z, date)
df$x = as.factor(df$x)
fig <- plot_ly(df, x = ~y, y = ~z)
fig <- fig %>% add_markers(marker = list(line = list(color = "black", width = 1)))
fig <- fig %>% layout(
  title = "Drop down menus - Plot type",
  xaxis = list(domain = c(0.1, 1)),
  yaxis = list(title = "y"),
  updatemenus = list(
    list(
      y = 0.8,
      buttons = list(
        
        list(method = "restyle",
             args = list("type", "scatter"),
             label = "Scatter"),
        
        list(method = "restyle",
             args = list("type", "histogram2d"),
             label = "2D Histogram")))
  ))

fig
fig <- plot_ly(df, x = ~date)
fig <- fig %>% add_lines(y = ~y, name = "A")
fig <- fig %>% add_lines(y = ~z, name = "B", visible = F)
fig <- fig %>% layout(
  title = "Drop down menus - Styling",
  xaxis = list(domain = c(0.1, 1)),
  yaxis = list(title = "y"),
  updatemenus = list(
    list(
      y = 0.8,
      buttons = list(
        
        list(method = "restyle",
             args = list("line.color", "blue"),
             label = "Blue"),
        
        list(method = "restyle",
             args = list("line.color", "red"),
             label = "Red")))
  )
)

fig