The goal of this vignette is to explain how to use the mgx2r package and give example of data visualisation with Plotly. It introduces the modified_read.ply() and modified_read.cellGraph() functions that allow to read the .ply files generated by MorphoGraphX and to use further their content, for instance, by visualising the mesh(es) or by doing statistics on the cell graph dataframes. For time serie visualisation, see the time serie vignette.
N.B: this package also include a function to write an R 3D object as a .ply mesh readable by MorphoGraphX, but I will not talk about it in this vignette.

Librairies needed

This vignette requires the mgx2r package, as well as some other additionnal packages. Plotly is a package for displaying 3D interactive graphs, the other packages are needed for colors (colorRamps and RColorBrewer), and for coding (magrittr, dplyr and glue).

To install {cellviz3d}:

Loading data

Some .ply demonstration data coming from my PhD thesis are attached to this package and used here in the vignette. This dataset is a timelapse recording of the development of a shoot apical meristem of the plant expressing a membrane marker. I took one 3D stack every 12h and have 5 timepoints in total. For more information regarding the generation of this dataset, see"mgx2r-package").

Here, in this first vignette, we I will select the first timepoint only. I have one .ply for the mesh and one .ply for the cellGraph.

As generating following plots with the full dataset might be slow, you can try with the cropped dataset.

Mesh and cell graph (e.g. cells and edges properties)

I load the .ply mesh with the modified_read.ply() function. This function is a modified version of read.ply function from geomorph R package to specifically read MGX ply files. I takes in account the fact that each triangular face of the mesh can get several colors (one for the label, one for the fluorescent signal projected on the mesh -membrane or microtubules-…).

Over the rest of the vignette I will only show examples of visualisation with Plotly, but there is another 3D library in R called RGL.


To change mesh color and display the new color, you can use the following command.

Information relative to cells and cell walls (resp. vertices and edges of the cell graph) are stored in a second .ply that I read with the modified_read.cellGraph() function that I wrote myself. The modified_read.cellGraph() function reads the cell graph .ply and extract two dataframes (one for the vertices informations and one for the edges informations). These two dataframes are then combined into a list.

N.B.: to see the content of one of these function, just type its name without the parentheses.

Last but not least, I am retrieving the location of the cell centers to display the cell ID at their location.

Displaying the mesh with plotly

To display the mesh with cell labels

Colors of the cell labels are set from the HEX color codes stored in myMesh$allColors$Col_label. There is always three colors: one per vertex. Two are identica, and usually black with MGX (“#000000” HEX code).

Without the cell labels

Default color of the mesh and opacity are set in the defaultColor parameter of the plotlyMesh() function (see ?plotlyMesh for more informations).

Displaying specific info from cellGraph on the mesh

The cell graph contains many information that can be added to the 3D visualisation of the mesh. I classified these information in two categories: scalars (e.g. numbers, such as growth rate, area…) and tensors (microtubule orientation, growth directions, curvature…). Below I give two examples, one with the areas and one with the principal direction of growth. If my scripts are correct, I should be able to display any scalar as for area, and any tensors, as for the principal direction of growth.

Scalar info (area, growth rate…)

p2 <- plotlyMesh(meshExample = myMesh, 
           meshColors = left_join(myMesh$it_label, myCellGraph$vertices) %>%
             select(., GeometryArea),
           meshCellcenter =  meshCellcenter
) %>%
  layout(scene =
             aspectmode = "data"

Vector/tensor info (principal dir of curvature…)

This part of the code is quite new and provide tools to visualise tensors, such as growth direction or curvature direction on any kind of mesh (without label, with cell label, with heatmap colors…), as long as it is already converted to a plot with plotlyMesh. The code below has not been tested extensively yet.

Drawing cell contours

As some may be also interested by drawing the cell contours, I have added an example here. This kind of graph is quite ressource consuming, as it is drawing each edge one by one, as a segment. Here in this example, there is 5151 edges. This could be useful if you are looking at the accumulation of a given protein (for instance PIN1) at the membrane. The information would be stored in the edges dataframe of the cell graph and I could use it to make a heatmap on the cell contours.