Skip to content

ggplot dendrogram cannot be added to plotly #61

Closed
@FMKerckhof

Description

@FMKerckhof

Hi, I am not able to transform a specific ggplot2 in R to plotly using the api. After having installed and run library(plotly) without any issues I ran the following code in Rstudio server:

hc<-hclust(dist(mtcars),method="ward.D2")
k <- 3
dendr <- dendro_data(hc,type="rectangle")
clust<- cutree(hc,k=k)
clust.df <- data.frame(label=names(clust), cluster=factor(clust))
# dendr[["labels"]] has the labels, merge with clust.df based on label column
dendr[["labels"]] <- merge(dendr[["labels"]],clust.df, by="label")
rect <- aggregate(x~cluster,label(dendr),range)
rect <- data.frame(rect$cluster,rect$x)
ymax <- mean(hc$height[length(hc$height)-((k-2):(k-1))])
# plot the dendrogram; note use of color=cluster in geom_text(...)
ggdendtest<- ggplot() + 
geom_segment(data=segment(dendr), aes(x=x, y=y, xend=xend, yend=yend)) + 
geom_text(data=label(dendr), aes(x, y, label=label, hjust=-0.1,
                                   color=cluster), size=4) +
geom_rect(data=rect, aes(xmin=X1-.3, xmax=X2+.3, ymin=0, ymax=ymax), 
            color="red", fill=NA)+
coord_flip() + scale_y_reverse(expand=c(0.2, 0)) + 
ylab("Distance") +
theme(axis.line.y=element_blank(),
        axis.ticks.y=element_blank(),
        axis.text.y=element_blank(),
        axis.title.y=element_blank(),
        panel.background=element_rect(fill="white"),
        panel.grid=element_blank(),
        legend.title=element_blank())


ggpy<-plotly()
ggpy.r<-ggpy$ggplotly(ggdendtest)
ggpy.r$response$url

This results in the following errors:

Error in eval(expr, envir, enclos) : object 'size' not found
In addition: Warning messages:
1: In layer2traces(L, df, misc, trace.list$plot) :
  Conversion not implemented for geom_text (basic geom_text), ignoring. Please open     an issue with your example code at https://github.com/ropensci/plotly/issues
2: In layer2traces(L, df, misc, trace.list$plot) :
  Conversion not implemented for geom_rect (basic geom_rect), ignoring. Please open an issue with your example code at https://github.com/ropensci/plotly/issues

Following the suggestion I opened an issue, hoping anyone can help me out.

Further info

The output of my sessionInfo() is:

 R version 3.1.0 (2014-04-10)
 Platform: x86_64-pc-linux-gnu (64-bit)

 locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C            LC_COLLATE=C         LC_MONETARY=C       
 [6] LC_MESSAGES=C        LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C         LC_TELEPHONE=C      
 [11] LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

 attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     

 other attached packages:
  [1] ggdendro_0.1-14       cluster_1.15.2        plotly_0.4            RJSONIO_1.2-0.2       RCurl_1.95-4.1       
 [6] bitops_1.0-6          devtools_1.5          extrafont_0.16        RColorBrewer_1.0-5    scales_0.2.4         
 [11] vegan_2.0-10          lattice_0.20-29       permute_0.8-3         splitstackshape_1.2.0 data.table_1.9.2     
 [16] BurStMisc_1.00        reshape2_1.4          xlsx_0.5.5            xlsxjars_0.6.0        rJava_0.9-6          
 [21] ggplot2_0.9.3.1       plyr_1.8.1           

 loaded via a namespace (and not attached):
 [1] MASS_7.3-32      Rcpp_0.11.1      Rttf2pt1_1.3     colorspace_1.2-4 digest_0.6.4     evaluate_0.5.5   extrafontdb_1.0 
 [8] formatR_0.10     grid_3.1.0       gtable_0.1.2     httr_0.3         knitr_1.6        labeling_0.2     memoise_0.2.1   
[15] munsell_0.4.2    parallel_3.1.0   proto_0.3-10     stringr_0.6.2    tools_3.1.0      whisker_0.3-2  

I am running R and Rstudio server (v. 0.98.501) on an Ubuntu 12.04 server LTS system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions