################################################################################ # # # Three dimensional scatterplots in loon # # ################################################################################ # # # # # Two separate examples will be given # # # # ################################################################################ # # # Example 1: Human immunoglobulin G1 antibody molecule # igg1 # ################################################################################ # library(loon) # This data is available from the loon.data package # # Note: there are several data sets in loon.data # see http://great-northern-diver.github.io/loon.data/ # or in R # browseURL("http://great-northern-diver.github.io/loon.data/reference") # library(loon.data) # The data data("igg1") # # variable names # names(igg1) # # structure # str(igg1) # Most variables are factors, x, y, z are coordinates # For more information, see help(igg1) # statistical summary # summary(igg1) # # Detailed contents in RStudio using # View(igg1) ######## # # L_plot3D() # ######## # from the variables in igg1, an interesting itemlabel # could be constructed (for a "tooltip") # atom_info <- with(igg1, paste0(recordType, ": ", name, "\n", # Note newline characters "Residue: ", residue, "\n", "Residue Name: ", residueName, "\n", "Group: ", group, "\n", "Chain ID: ", chainID) ) p3d <- with(igg1, l_plot3D(x = x, y = y, z = z, # Rest of arguments are as in l_plot() itemLabel = atom_info, showItemLabels = FALSE, # <- show tool tips? showLabels = TRUE, # <- show axis labels and title? showGuides = TRUE, linkingGroup = "igg1", title = "human IgG1 molecule") ) # # SUGGESTION: Make the window square shaped # # NOTE: the inspector is (nearly) identical to the l_plot() inspector # # # TRY: # # 1. Turn ON itemLabels and hover over a few of the points. # - Can you locate points that are "HETATM"? # # 2. Turn OFF itemLabels # # # On the plot # # 3. Press the letter key. # - what happened? # # You are now in "Rotation Mode" # # Press the key again. # You are now NOT in "Rotation Mode" # # 4. Put the plot into "Rotation Mode" # # Press the RIGHT ARROW key. Hold it down. # Release the key. # What has happened to the axis labels? # # Press the UP ARROW key. Hold it down. # Release the key. # What has happened to the axis labels? # # Using the DOWN ARROW and then the LEFT ARROW # Try and return the molecule to its original position. # # TURN OFF rotation mode. # # 5. On the INSPECTOR, near the bottom, # there is a NEW "move" button just for 3D plots. # It is supposed to be a 3D axis. # # Press the axis button. What happened? # This is ALWAYS available. # # 6. Turn ON rotation mode. # # 7. With the LEFT mouse button pressed, move the molecule. # # NOTE that brushing and sweeping are not available # in rotation mode. # # 8. With the RIGHT mouse button pressed, move the molecule. # # Move it away from the axes. # # 9. Rotate the molecule. # NOTE the centre of rotation. # # 10. Click on the axes button in the inspector. # How does the molecule change? # # Scale to plot. # # 11. Turn off rotation. # # # hrecord <- with(igg1, l_hist(recordType, title = "Record type", linkingGroup = "igg1") ) # # TRY: # # 1. Select the ATOM records and deactivate them. # # 2. Zoom in on the remaining points # Centre them on the 3D axis # Rotate the points to reveal their geometric structure. # # hresidue <- with(igg1, l_hist(residue, swapAxes = TRUE, title = "Residue", linkingGroup = "igg1") ) # # 3. The remaining residues appear to be # two high frequency and two low frequency pairs # # - Colour the high frequency pair dark blue and light blue # - Colour the low frequency pair red and pink # # Rotate the point cloud to reveal the symmetries. # # 4. Using the itemLabels, # - to what "Group" and "Chain ID" do the HETATMS # appear to belong. # # Turn OFF itemLabels # # 5. In the 3d plot INSPECTOR # - reactivate all points # - relocate points to original position # - scale to plot # hchainID <- with(igg1, l_hist(chainID, title = "Chain", linkingGroup = "igg1") ) # 6. Deactivate all points in Chain "C". # # 7. In the INSPECTOR of the 3d plot # - select all points # - increase their size until neighbouring points touch # that is "chains" of beads appear. # # 8. In the chainID histogram # - colour chain H light brown # - colour chain I dark brown # - colour chain L light green # - colour chain M dark green # # Rotate the plot to reveal the chain structure symmetry # # The distribution of the various residues can be # now better appreciated from interactions with the # residue histogram. # # # Chains and their sequences: pChains <- with(igg1, l_plot(x = residueSequenceNum, y = chainID, glyph = "ocircle", xlabel = "sequence number", ylabel = "chain", title = "Chain sequences", linkingGroup = "igg1") ) # 9. Brush each chain (or pairs of chains) # folowing the sequence orders. # # # # # # NOTE: # # - There is a LOT more geometric structure here. # For example, f_p3d <- with(igg1, l_plot3D(x, y, z, by = chainID)) # could be used to illustrate the symmetry of matched chains. # # - There is another molecule in loon.data that has even # richer information and structure. # The SCmolecule is a protein-DNA combination. # ################################################################################ # # # # # # # # ################################################################################ # # # Example 2: Quakes data from R # quakes # ################################################################################ # # In addition to three dimensional plots, this example involves maps. # library(loon) library(maps) # # the data str(quakes) help(quakes) View(quakes) # # Begin with a plot of the quake locations. # quakeNos <- paste0("quake: ", 1:nrow(quakes)) p <- with(quakes, l_plot(x = long, y = lat, xlabel = "longitude", ylabel = "latitude", glyph = "ocircle", # <- points will be open circles size = 6, linkingGroup = "quakes", itemLabel = quakeNos, showGuides = TRUE, title = "Earthquake locations") ) # get map of nearby islands (from maps package) library(maps) NZFijiMap <- map("world2", regions=c("New Zealand", "Fiji", "Tonga", "New Caledonia", "Vanuatu", "Solomon Islands", "Wallis and Futuna", "American Samoa"), plot=FALSE) # layer map onto the scatterplot p l_layer(p, NZFijiMap, label = "Tonga trench islands", color = "lightgreen", index = "end") # # TRY # 1. Move the map around to see each island # - on the scatterplot (RIGHT mouse on background) # - on the World View (either mouse button) # # 2. Zoom in on New Zealand's large North Island # (also called Te Ika-a-Maui) # # 3. Scale the scatterplot to "world" # # 4. Scale the scatterplot to "plot" # ######## # # Including the Earthquake depths # # NOTE: # There are three different measurements here # - lat in degrees latitude # - long in degrees longitude # - depth in kilometres # # These need to be standardized to at least be on a common scale # # Using l_scale3D(), variables are transformed to fit # within a (hyper-) cube (default transformation; see help(l_scale3D)). # # 3d plot x = longitude, y = latitude, and z = depth of quakes (note rescaling) # p3D <- with(l_scale3D(quakes), # scaled the data to common ranges l_plot3D(x = long, y = lat, z = depth, xlabel = "longitude", ylabel = "latitude", zlabel = "depth", itemLabel = quakeNos, showGuides = TRUE, color = "steelblue", glyph = "ccircle", size = 6, linkingGroup = "quakes") ) # # Question: # Why did the points in the map change colour? # Why did the shape of the points in the map NOT change? # # # # TRY # On the 3D plot # # 1. Put the 3D plot in rotation mode (press the key ) # # 2. Use the DOWN arrow key to rotate the # latitude into the depth # NOTE: # When done, # - vertical label should have -1.000 depth # and zero longitude and latitude # - horizontal label should have 1.000 longitude # and zero latitude and depth. # 3. Move the points up so they all fit in the window # (RIGHT mouse on background) # # 4. Turn OFF rotation mode # # 5. Select the deepest quakes. # Any geographic pattern? # # 6. Select the shallowest quakes. # Any geographic pattern? # # 7. With a wide but narrow horizontal brush, # brush the plot from top to bottom and back. # Any geographic pattern? # # Turn OFF the brush # # On the map # # 8. Select ALL quakes in the NORTH WEST quadrant of the map # Deactivate them. # # Those that remain in the EAST are associated with the Tonga Trench. # # 9. Select ALL the remaining points in the map # Scale to selected. # # Deselect all. # # 10. With a wide but VERY narrow horizontal brush, # brush the plot from top to bottom and back. # Question: # - what is the brush conditioning on? # - what pattern does it produce in the 3D plot? # # 11. Reshape the brush to a small square and # select all points in the "question mark" shape. # # Invert the selection and deactivate the # resulting selected points # # Select all the remaining points and # Scale to selected. # # 12. Using the brush and selecting groups as necessary, # divide the points into three different coloured # groups according to whether they are in the # northern most group, the central group, or # the southern group (the dot of the original question mark.) # # Turn OFF the brush # # # On the 3D plot: # # 13. Centre the remaining points near the axes # Do NOT zoom; do NOT rescale # # 14. Put the plot in rotation mode # Using the RIGHT arrow key rotate the points until the # three colours separate as much as possible. # # You may SCROLL (no modifier keys) to better see the # separation. # # NOTE # # - Two of the three colours represent tectonic shearing in one direction # The third colour shows tectonic shearing in a different direction as # one tectonic plate moves under the other. # ################################################################################ ################################################################################ # # NOTE # # The above examples are also explored in the video # # "3D interactive scatterplots in loon" https://youtu.be/mMJllGOuDLY # # See references there for more scientific information, especially on quakes # ################################################################################