在输出情节时出现错误。

时间:2023-02-02 22:52:48

I have this data (sample of the first 20 rows):

我有这个数据(前20行样本):

  • Codering variable value
  • 编码器变量值
  • 1 Z1 Week.0 0
  • 1 Z1 Week.0 0
  • 2 Z2 Week.0 0
  • 2 Z2 Week.0 0
  • 3 Z3 Week.0 0
  • 3 Z3 Week.0 0
  • 4 Z4 Week.0 0
  • 4 Z4 Week.0 0
  • 5 Z5 Week.0 0
  • 5 Z5 Week.0 0
  • 6 Z6 Week.0 0
  • 6 Z6 Week.0 0
  • 7 Z7 Week.0 0
  • 7 Z7 Week.0 0
  • 8 Z8 Week.0 0
  • 8 Z8等车型后Week.0亨里克·菲克斯0
  • 9 Z9 Week.0 0
  • 9 Z9 Week.0 0
  • 10 Z101 Week.0 NA
  • 10 Z101 Week.0 NA
  • 11 Z102 Week.0 NA
  • 11 Z102 Week.0 NA
  • 12 Z1 Week.1 0
  • 12 Z1 Week.1 0
  • 13 Z2 Week.1 0
  • 13 Z2 Week.1 0
  • 14 Z3 Week.1 0
  • 14 Z3 Week.1 0
  • 15 Z4 Week.1 0
  • 15 Z4 Week.1 0
  • 16 Z5 Week.1 0
  • 16 Z5 Week.1 0
  • 17 Z6 Week.1 0
  • 17 Z6 Week.1 0
  • 18 Z7 Week.1 0
  • 18 Z7 Week.1 0
  • 19 Z8 Week.1 0
  • 19 Z8等车型后Week.1 0亨里克·菲克斯

and I plot it using:

我把它画出来

pZ <- ggplot(zmeltdata,aes(x=variable,y=value,color=Codering,group=Codering)) + 
  geom_line()+
  geom_point()+
  theme_few()+
  theme(legend.position="right")+
  scale_color_hue(name = "Treatment group:")+
  scale_y_continuous(labels = percent)+
  ylab("Germination percentage")+
  xlab("Week number")+
  labs(title = "Z. monophyllum germination data")
pZ

The graph displays just fine:

图形显示的很好:

在输出情节时出现错误。

Yet when I want to export this to Plot.ly I get the following errors:

但当我想把它导出为图时。我得到了以下错误:

> py <- plotly()
> response<-py$ggplotly(pZ)
Error in if (all(xcomp) && all(ycomp)) { : 
  missing value where TRUE/FALSE needed
In addition: Warning message:
In trace.list[[lind[1]]]$y == trace.list[[lind[2]]]$y :
  longer object length is not a multiple of shorter object length

And I have searched for these errors, yet the explanation thoroughly confuses me. "The missing value where TRUE/FALSE needed." is supposed to occur if you use logical termms as IF/ELSE/TRUE/FALSE and such in your process, which I don't at all! Even when checking for any NA's in the value of the graph I get:

我已经寻找了这些错误,但是这个解释让我很困惑。如果你在你的过程中使用了逻辑的termms,而我根本就没有这样做,那么你就应该在这个过程中发生“丢失的值”。甚至当我检查任何NA的值时,我得到:

> is.na(pZ)
       data      layers      scales     mapping       theme coordinates       facet    plot_env      labels 
      FALSE       FALSE       FALSE       FALSE       FALSE       FALSE       FALSE       FALSE       FALSE 

and the 'longer object length is not multiple of shorter object length' is supposed to pop up when you have objects of different lengths, but I'm only using 1 object with 3 rows that have exactly the same length.. The value of the graph does give me a NULL when I ask for those rows, but that is supposed to happen..

当你有不同长度的对象时,“更长的对象长度不是多个短的对象长度”应该会弹出,但是我只使用了一个具有相同长度的3行的对象。当我要求这些行时,图的值确实给了我一个空值,但这是应该发生的。

> nrow(zmeltdata)
[1] 143
> nrow(test)
NULL

All in all, I'm very confused and don't know how to correctly handle these errors, could someone elaborate?

总之,我很困惑,不知道如何正确处理这些错误,有人能详细说明一下吗?

Thanks for your time.

谢谢你的时间。

EDIT: I have tried to export a different graph to Plot.ly using a random sample of 1:100 and that worked just fine, I'm pretty sure the error is in my data, I just can't figure out how to fix it.

编辑:我试图导出一个不同的图来绘图。使用一个1:100的随机样本,这很好,我很确定这个错误在我的数据中,我只是不知道怎么解决它。

EDIT2: In response to @Gregor:

EDIT2:回应@Gregor:

> dput(head(zmeltdata, 20))
structure(list(Codering = structure(c(16L, 19L, 20L, 21L, 22L, 
23L, 24L, 25L, 26L, 17L, 18L, 16L, 19L, 20L, 21L, 22L, 23L, 24L, 
25L, 26L), .Label = c("B1", "C2", "C3", "C8", "M1", "M101", "M102", 
"M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "Z1", "Z101", 
"Z102", "Z2", "Z3", "Z4", "Z5", "Z6", "Z7", "Z8", "Z9"), class = "factor"), 
    variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Week.0", 
    "Week.1", "Week.2", "Week.3", "Week.4", "Week.5", "Week.6", 
    "Week.7", "Week.8", "Week.9", "Week.10", "Week.11", "Week.12"
    ), class = "factor"), value = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 
    NA, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("Codering", 
"variable", "value"), row.names = c(NA, 20L), class = "data.frame")

And the tail:

尾巴:

> dput(tail(zmeltdata, 43))
structure(list(Codering = structure(c(19L, 20L, 21L, 22L, 23L, 
24L, 25L, 26L, 17L, 18L, 16L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 
26L, 17L, 18L, 16L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 17L, 
18L, 16L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 17L, 18L), .Label = c("B1", 
"C2", "C3", "C8", "M1", "M101", "M102", "M2", "M3", "M4", "M5", 
"M6", "M7", "M8", "M9", "Z1", "Z101", "Z102", "Z2", "Z3", "Z4", 
"Z5", "Z6", "Z7", "Z8", "Z9"), class = "factor"), variable = structure(c(10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 13L), .Label = c("Week.0", "Week.1", "Week.2", "Week.3", 
"Week.4", "Week.5", "Week.6", "Week.7", "Week.8", "Week.9", "Week.10", 
"Week.11", "Week.12"), class = "factor"), value = c(0.1, 0.06, 
0.05, 0.09, 0.04, 0.08, 0.05, 0.08, 0, 0, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c("Codering", 
"variable", "value"), row.names = 101:143, class = "data.frame")

I am not at all surprised by these, there are quite some NA's in the dataset but they shouldn't prove to be an issue, since I have used a similar (bigger) dataset before.

我一点也不惊讶,在数据集中有相当多的NA,但它们不应该被证明是一个问题,因为我以前使用过类似的(更大的)数据集。

And I also have the .csv file for you to use if you wish: https://www.mediafire.com/?jij1vlp14a29ntt

我也有.csv文件供您使用:https://www.mediafire.com/?jij1vlp14a29ntt。

1 个解决方案

#1


2  

The issue is about handling NA's... I got https://plot.ly/~marianne2/417/z-monophyllum-germination-data/ by running the following code:

问题是如何处理NA的…我得到了https://plot。ly/~marianne2/417/z-单极-种子-数据/通过运行以下代码:

pZ <- ggplot(na.omit(zmeltdata), aes(x=variable, y=value, color=Codering,
                                 group=Codering)) +
  geom_line() +
  geom_point() +
  # theme_few() +
  theme(legend.position="right") +
  scale_color_hue(name="Treatment group:") +
  # scale_y_continuous(labels = percent) +
  ylab("Germination percentage") +
  xlab("Week number") +
  labs(title="Z. monophyllum germination data")

py$ggplotly(pZ, kwargs=list(fileopt="overwrite", filename="test_zdata"))

Note that I had to comment out theme_few() and scale_y_continuous(labels = percent) because from loading only "ggplot2", I would get the following errors:

注意,我必须注释掉theme_few()和scale_y_continuous(标签= %),因为只加载“ggplot2”,我将得到以下错误:

Error: could not find function "theme_few"

and

Error in structure(list(call = match.call(), aesthetics = aesthetics,  : 
object 'percent' not found

respectively. I guess these are dependency issues (maybe you're using a version of "ggthemes"?).

分别。我想这些是依赖性问题(也许您正在使用“ggtopic”的版本)。

I don't know what kind of magic theme_few() does, but if I don't use na.omit() on zmeltdata, my pZ plot looks like this: 在输出情节时出现错误。

我不知道theme_few()有什么神奇之处,但如果我不使用nai .省略()在zmeltdata上,我的pZ图形就像这样:

Eww, "Week.10" comes after "Week.1" instead of after "Week.9"... So you wouldn't want to send this to plotly anyway! So I cannot exactly reproduce your ggplot example. But I wonder if you really want to keep these NA's (the CSV itself reads "NA", I was expecting blank "cells"). Don't you want to pre-process these anyway?

"Week.10"是在"Week.1"之后,而不是"Week.9"之后。所以无论如何你都不会想要把这个发送出去!所以我不能完全复制你的ggplot例子。但我不知道你是否真的想保留这些NA的(CSV本身读取“NA”,我期待的是空白的“cell”)。你不想预先处理这些吗?

Note that I get the following warning message when I don't use na.omit() on zmeltdata:

注意,当我不在zmeltdata中使用na.省略()时,我得到以下警告消息:

Warning messages:
1: Removed 20 rows containing missing values (geom_path).
2: Removed 47 rows containing missing values (geom_point).

Again, beyond pure displaying/plotting considerations, since this looks like scientific data, wouldn't you want to number weeks with actual numbers, or pad the digits if you really want a string? ("Week.01", "Week.02", etc.) And it looks like the missing data is all trailing... There's just no data (yet) for weeks 10+, right?

除了纯粹的显示/绘图方面的考虑之外,因为这看起来像科学数据,你不想用实际数字来数周,或者如果你真的想要一个字符串的话,你想要填充数字吗?(“Week.01”,“Week.02”,等等),看起来缺失的数据都在后面……目前还没有数据(但是)10周以上,对吧?

Thanks for reporting,

谢谢你的报告,

Marianne

玛丽安

#1


2  

The issue is about handling NA's... I got https://plot.ly/~marianne2/417/z-monophyllum-germination-data/ by running the following code:

问题是如何处理NA的…我得到了https://plot。ly/~marianne2/417/z-单极-种子-数据/通过运行以下代码:

pZ <- ggplot(na.omit(zmeltdata), aes(x=variable, y=value, color=Codering,
                                 group=Codering)) +
  geom_line() +
  geom_point() +
  # theme_few() +
  theme(legend.position="right") +
  scale_color_hue(name="Treatment group:") +
  # scale_y_continuous(labels = percent) +
  ylab("Germination percentage") +
  xlab("Week number") +
  labs(title="Z. monophyllum germination data")

py$ggplotly(pZ, kwargs=list(fileopt="overwrite", filename="test_zdata"))

Note that I had to comment out theme_few() and scale_y_continuous(labels = percent) because from loading only "ggplot2", I would get the following errors:

注意,我必须注释掉theme_few()和scale_y_continuous(标签= %),因为只加载“ggplot2”,我将得到以下错误:

Error: could not find function "theme_few"

and

Error in structure(list(call = match.call(), aesthetics = aesthetics,  : 
object 'percent' not found

respectively. I guess these are dependency issues (maybe you're using a version of "ggthemes"?).

分别。我想这些是依赖性问题(也许您正在使用“ggtopic”的版本)。

I don't know what kind of magic theme_few() does, but if I don't use na.omit() on zmeltdata, my pZ plot looks like this: 在输出情节时出现错误。

我不知道theme_few()有什么神奇之处,但如果我不使用nai .省略()在zmeltdata上,我的pZ图形就像这样:

Eww, "Week.10" comes after "Week.1" instead of after "Week.9"... So you wouldn't want to send this to plotly anyway! So I cannot exactly reproduce your ggplot example. But I wonder if you really want to keep these NA's (the CSV itself reads "NA", I was expecting blank "cells"). Don't you want to pre-process these anyway?

"Week.10"是在"Week.1"之后,而不是"Week.9"之后。所以无论如何你都不会想要把这个发送出去!所以我不能完全复制你的ggplot例子。但我不知道你是否真的想保留这些NA的(CSV本身读取“NA”,我期待的是空白的“cell”)。你不想预先处理这些吗?

Note that I get the following warning message when I don't use na.omit() on zmeltdata:

注意,当我不在zmeltdata中使用na.省略()时,我得到以下警告消息:

Warning messages:
1: Removed 20 rows containing missing values (geom_path).
2: Removed 47 rows containing missing values (geom_point).

Again, beyond pure displaying/plotting considerations, since this looks like scientific data, wouldn't you want to number weeks with actual numbers, or pad the digits if you really want a string? ("Week.01", "Week.02", etc.) And it looks like the missing data is all trailing... There's just no data (yet) for weeks 10+, right?

除了纯粹的显示/绘图方面的考虑之外,因为这看起来像科学数据,你不想用实际数字来数周,或者如果你真的想要一个字符串的话,你想要填充数字吗?(“Week.01”,“Week.02”,等等),看起来缺失的数据都在后面……目前还没有数据(但是)10周以上,对吧?

Thanks for reporting,

谢谢你的报告,

Marianne

玛丽安