0

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

  • Codering variable value
  • 1 Z1 Week.0 0
  • 2 Z2 Week.0 0
  • 3 Z3 Week.0 0
  • 4 Z4 Week.0 0
  • 5 Z5 Week.0 0
  • 6 Z6 Week.0 0
  • 7 Z7 Week.0 0
  • 8 Z8 Week.0 0
  • 9 Z9 Week.0 0
  • 10 Z101 Week.0 NA
  • 11 Z102 Week.0 NA
  • 12 Z1 Week.1 0
  • 13 Z2 Week.1 0
  • 14 Z3 Week.1 0
  • 15 Z4 Week.1 0
  • 16 Z5 Week.1 0
  • 17 Z6 Week.1 0
  • 18 Z7 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:

enter image description here

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:

> 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..

> 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.

EDIT2: In response to @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.

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

4

1 回答 1

2

问题是关于处理 NA 的......我通过运行以下代码获得了https://plot.ly/~marianne2/417/z-monophyllum-germination-data/ :

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"))

请注意,我必须注释掉theme_few()scale_y_continuous(labels = percent)因为仅加载“ggplot2”,我会收到以下错误:

Error: could not find function "theme_few"

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

分别。我猜这些是依赖问题(也许您使用的是“ggthemes”版本?)。

我不知道是什么样的魔法theme_few(),但如果我不使用na.omit()on zmeltdata,我的pZ情节看起来像这样: 在此处输入图像描述

Eww,“Week.10”在“Week.1”之后而不是在“Week.9”之后......所以你无论如何都不想把它发送给 plotly!所以我不能完全重现你的 ggplot 例子。但我想知道你是否真的想保留这些 NA(CSV 本身读取“NA”,我期待空白的“单元格”)。你不想对这些进行预处理吗?

请注意,当我不使用na.omit()on时,会收到以下警告消息zmeltdata

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

同样,除了纯粹的显示/绘图考虑之外,由于这看起来像科学数据,您是否不想用实际数字对周数进行编号,或者如果您真的想要一个字符串则填充数字?(“Week.01”、“Week.02”等)而且看起来丢失的数据都在尾随......第 10 周以上还没有数据,对吧?

感谢举报,

玛丽安

于 2015-01-09T16:50:26.780 回答