0
votes

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

1
Please share your data in a more reproducible format... if you use dput(head(zmeltdata, 20)) it will look ugly but be very useful (we'll be able to copy/paste it into R and know what all the column classes are). Also, if your problem is in your data and your first 100 rows work, maybe you should be posting (or just examining) the last 43 rows of your data (dput(tail(zmeltdata, 43))) - Gregor Thomas
No problem @Gregor: I have included the datafile itsself if you are interested. And for the cautious, a virus scan: virustotal.com/en/file/… - Yoeri

1 Answers

2
votes

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

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:

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

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: enter image description here

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?

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

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?

Thanks for reporting,

Marianne