Help with 3d scatter plot

322 views
Skip to first unread message

Zhiyuan Tian

unread,
Sep 22, 2016, 8:07:44 PM9/22/16
to Davis R Users' Group
Hello, I got a code online to make a 3D plot like this

library(plotly)
plot_ly(data = iris, x = Sepal.Length, y = Sepal.Width, z = Petal.Width, color = Species, type = "scatter3d", mode = "markers")
However, I met a problem when I run it

Error in as.character(tools:::httpdPort) : cannot coerce type 'closure' to vector of type 'character'

Does anyone know how to deal with this?

Thanks ahead!!!

Brandon Hurr

unread,
Sep 22, 2016, 9:23:22 PM9/22/16
to davi...@googlegroups.com
Zhiyuan, 

Firstly, this stuff is under very active development so stuff is changing more rapidly than most can keep up with (except the developers). I say this mainly because the way you reference variables appears to be as expressions. 

In ?plot_ly, it shows this in the examples. 
plot_ly(z = ~volcano, type = "surface")

So, I rewrote your statement with that in mind and I got a plot. 
plot_ly(data = iris, x = ~Sepal.Length, y = ~Sepal.Width, z = ~Petal.Width, color = ~Species, type = "scatter3d", mode = "markers")

It would very much help if we knew what version of the various packages you are using if this does not solve your problem. 

B

devtools::session_info()
Session info -----------------------------------------------------------------------------------
 setting  value                                      
 version  R version 3.3.1 Patched (2016-06-22 r70818)
 system   x86_64, darwin13.4.0                       
 ui       AQUA                                       
 language (EN)                                       
 collate  en_US.UTF-8                                
 tz       America/Los_Angeles                        
 date     2016-09-22                                 

Packages ---------------------------------------------------------------------------------------
 package      * version     date       source                          
 assertthat     0.1         2013-12-06 CRAN (R 3.3.0)                  
 base64enc      0.1-3       2015-07-28 CRAN (R 3.3.0)                  
 colorspace     1.2-6       2015-03-11 CRAN (R 3.3.0)                  
 curl           2.0         2016-09-17 cran (@2.0)                     
 DBI            0.5-1       2016-09-10 cran (@0.5-1)                   
 devtools       1.11.1.9000 2016-06-23 Github (hadley/devtools@d247c17)
 digest         0.6.10      2016-08-02 cran (@0.6.10)                  
 dplyr        * 0.5.0.9000  2016-09-23 Github (hadley/dplyr@6153e13)   
 ggplot2      * 2.1.0.9000  2016-09-23 Github (hadley/ggplot2@70ae16c) 
 git2r          0.15.0      2016-05-11 CRAN (R 3.3.0)                  
 gtable         0.2.0       2016-02-26 CRAN (R 3.3.0)                  
 htmltools      0.3.5       2016-03-21 CRAN (R 3.3.0)                  
 htmlwidgets    0.7         2016-08-02 cran (@0.7)                     
 httr           1.2.1       2016-07-03 cran (@1.2.1)                   
 jsonlite       1.1         2016-09-14 cran (@1.1)                     
 knitr          1.13        2016-05-09 CRAN (R 3.3.0)                  
 lazyeval       0.2.0.9000  2016-09-23 Github (hadley/lazyeval@c155c3d)
 magrittr       1.5         2014-11-22 CRAN (R 3.3.0)                  
 memoise        1.0.0       2016-01-29 CRAN (R 3.3.0)                  
 munsell        0.4.3       2016-02-13 CRAN (R 3.3.0)                  
 plotly       * 4.5.0       2016-09-23 Github (ropensci/plotly@66039c8)
 plyr           1.8.4       2016-06-08 CRAN (R 3.3.0)                  
 purrr          0.2.2.9000  2016-09-23 Github (hadley/purrr@8c72c35)   
 R6             2.1.3       2016-08-19 cran (@2.1.3)                   
 RColorBrewer   1.1-2       2014-12-07 CRAN (R 3.3.0)                  
 Rcpp           0.12.7      2016-09-05 cran (@0.12.7)                  
 scales         0.4.0       2016-02-26 CRAN (R 3.3.0)                  
 tibble         1.2-12      2016-09-23 Github (hadley/tibble@6d2bb08)  
 tidyr          0.6.0.9000  2016-09-23 Github (hadley/tidyr@3c9335b)   
 viridisLite    0.1.3       2016-03-12 cran (@0.1.3)                   
 withr          1.0.2       2016-06-20 CRAN (R 3.3.0)                  
 yaml           2.1.13      2014-06-12 CRAN (R 3.3.0)        


--
Check out our R resources at http://d-rug.github.io/
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.

Zhiyuan Tian

unread,
Sep 23, 2016, 7:37:02 PM9/23/16
to davi...@googlegroups.com
Hi Brandon,

Thanks for you help! I run the rewrite code and get another error like this:
Error in unique.default(cols) : unique() applies only to vectors

The version of package you mean R version? When I using ??plot_ly, it shows example like this:

data(economics, package = "ggplot2")
p <- plot_ly(economics, x = date, y = uempmed, type = "scatter", 
  showlegend = FALSE)

So maybe we are in the different version of R?
Thanks again for helping,
Tina

You received this message because you are subscribed to a topic in the Google Groups "Davis R Users' Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/davis-rug/FSTkyMv2Rj4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to davis-rug+unsubscribe@googlegroups.com.

Michael Hannon

unread,
Sep 24, 2016, 12:44:17 AM9/24/16
to davi...@googlegroups.com
I think that Brandon is asking for you to show us the output of the function "session_info()" as run on your computer.  Here's an example from my computer:

> library(plotly)
Loading required package: ggplot2

Attaching package: ‘plotly’

The following object is masked from ‘package:ggplot2’:

    last_plot

The following object is masked from ‘package:graphics’:

    layout

> library(devtools)
> session_info()
Session info -----------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.1 (2016-06-21)
 system   x86_64, linux-gnu           
 ui       X11                         
 language en_US                       
 collate  en_US.UTF-8                 
 tz       <NA>                        
 date     2016-09-23                  

Packages ---------------------------------------------------------------------------------------
 package     * version date       source        
 assertthat    0.1     2013-12-06 CRAN (R 3.2.1)
 base64enc     0.1-3   2015-07-28 CRAN (R 3.2.2)
 colorspace    1.2-6   2015-03-11 CRAN (R 3.2.0)
 devtools    * 1.12.0  2016-06-24 CRAN (R 3.3.1)
 digest        0.6.10  2016-08-02 CRAN (R 3.3.1)
 ggplot2     * 2.1.0   2016-03-01 CRAN (R 3.2.4)
 gridExtra     2.2.1   2016-02-29 CRAN (R 3.2.3)
 gtable        0.2.0   2016-02-26 CRAN (R 3.2.3)
 htmltools     0.3.5   2016-03-21 CRAN (R 3.2.4)
 htmlwidgets   0.7     2016-08-02 CRAN (R 3.3.1)
 httr          1.2.1   2016-07-03 CRAN (R 3.3.1)
 jsonlite      1.0     2016-07-01 CRAN (R 3.3.1)
 magrittr      1.5     2014-11-22 CRAN (R 3.2.0)
 memoise       1.0.0   2016-01-29 CRAN (R 3.2.3)
 munsell       0.4.3   2016-02-13 CRAN (R 3.2.3)
 plotly      * 3.6.0   2016-05-18 CRAN (R 3.3.1)
 plyr          1.8.4   2016-06-08 CRAN (R 3.3.0)
 R6            2.1.3   2016-08-19 CRAN (R 3.3.1)
 Rcpp          0.12.7  2016-09-05 CRAN (R 3.3.1)
 scales        0.4.0   2016-02-26 CRAN (R 3.2.3)
 tibble        1.2     2016-08-26 CRAN (R 3.3.1)
 tidyr         0.6.0   2016-08-12 CRAN (R 3.3.1)
 viridis       0.3.4   2016-03-12 CRAN (R 3.2.4)
 withr         1.0.2   2016-06-20 CRAN (R 3.3.1)

Zhiyuan Tian

unread,
Sep 24, 2016, 7:29:50 PM9/24/16
to davi...@googlegroups.com
Thanks for explanation! Here is my output for running the package "plotly"

> library(plotly)
Loading required package: ggplot2

Attaching package: ‘plotly’

The following object is masked from ‘package:ggplot2’:

    last_plot

The following object is masked from ‘package:graphics’:

    layout

Warning messages:
1: package ‘plotly’ was built under R version 3.2.5 
2: package ‘ggplot2’ was built under R version 3.2.5 

I still got the error like this:

> plot_ly(data = iris, x = Sepal.Length, y = Sepal.Width, z = Petal.Width, color = Species, type = "scatter3d", mode = "markers")
Error in as.character(tools:::httpdPort) : 
  cannot coerce type 'closure' to vector of type 'character'

Some guess for why this happened?

Tina

Brandon Hurr

unread,
Sep 24, 2016, 8:16:43 PM9/24/16
to davi...@googlegroups.com
Your R is out of date by about 4 months so there could be something there. 

Could you run the following in an empty R session and paste the output into your reply:

library(plotly)
sessionInfo()

I suspect you just have some out of date code. My first step would be updating R by downloading the latest (3.3.1). 
After install you'll need to reinstall your packages (I think). 

A suggestion:
install.packages("tidyverse")
install.packages("plotly")

This should get you mostly back to where you want to be (assuming you like the tidyverse) for this question.

Then try your code again and if you still have issues email back with the sessionInfo() requested above. 

B

Zhiyuan Tian

unread,
Sep 24, 2016, 9:36:28 PM9/24/16
to davi...@googlegroups.com
I update the R to 3.3.1, and the plot is showing! Thank you so much :-P
Reply all
Reply to author
Forward
0 new messages