banner



How To Draw 3d Plots In R

A 3D plot/graph is a plot that presents data points/surface on 3 axes in the attempt to show the relationship betwixt 3 variables. Each row in the data table is represented by a marker whose position depends on its values in the columns set on the X, Y, and Z axes. A 4th variable tin can be set to correspond to the colour or size of the markers/surface, thus adding yet another dimension to the plot.

There are many functions in R programming for creating 3D plots. In this post, I volition deliver an introduction to these functions, hopefully you can larn and develop it into an advance method. The libraries I used for this tutorial are:

library(plot3D) library(raster) library(rgl) library(plotly)

Think, If you haven't installed them, yous need to run the install.packages() function get-go.

I will use two set of data. the first is air quality data, that you can directly phone call in Rstudio (come across the complete script), and the second is a xyz data of a digital superlative data in Merapi volcano in Republic of indonesia. I have resampled the DEM data, and then information technology has 150 m mesh resolution, and the extent is about 30-50 km from the vent (I forgot ^^'). You can download the data hither.

This video shows the tutorial, and to copy or replicate the script, yous can check the space below the video.

Main script starts hither:

airquality -> data                #basic plot                scatter3D(x=data$Month, y=data$Ozone, z=information$Solar.R, bty = "1000",   pch = 20, cex = 2, ticktype = "detailed")                #put label                scatter3D(ten=data$Calendar month, y=data$Ozone, z=information$Solar.R, bty = "g",   pch = 20, cex = 2, ticktype = "detailed", clab="Solar rad.", xlab="Month",ylab= "Ozone", zlab="solar rad")                #change theme                scatter3D(x=information$Month, y=data$Ozone, z=data$Solar.R, bty = "b2",   pch = 20, cex = 2, ticktype = "detailed", clab="Solar rad.", xlab="Month",ylab= "Ozone", zlab="solar rad")                #change perspective                scatter3D(ten=data$Month, y=data$Ozone, z=data$Solar.R, bty = "b2",   pch = 20, cex = 2, ticktype = "detailed", clab="Solar rad.", xlab="Calendar month",ylab= "Ozone", zlab="solar rad", phi = 0)  scatter3D(x=data$Month, y=data$Ozone, z=data$Solar.R, bty = "b2",   pch = xx, cex = 2, ticktype = "detailed", clab="Solar rad.", xlab="Calendar month",ylab= "Ozone", zlab="solar rad", phi = 0, theta=30)                #using other variables                scatter3D(x=data$Temp, y=data$Ozone, z=information$Month, bty = "b2",   pch = xx, cex = ii, ticktype = "detailed", clab="Month", xlab="Month",ylab= "Ozone", zlab="solar rad", phi = 0, theta=30)                #create custom color for the legend                and customise information technology,                scatter3D(10=data$Temp, y=data$Ozone, z=data$Month, bty = "b2",   pch = twenty, cex = 2, ticktype = "detailed", clab="Month", xlab="Month",ylab= "Ozone", zlab="solar rad", phi = 0, theta=xxx,  col.var = data$Month,  col = c("blue", "greenish", "yellowish", "orange", "cherry"))  scatter3D(x=data$Temp, y=information$Ozone, z=data$Month, bty = "b2",   pch = twenty, cex = two, ticktype = "detailed", clab="Month", xlab="Month",ylab= "Ozone", zlab="solar rad", phi = 0, theta=30,  col.var = data$Month,  col = c("blue", "dark-green", "yellow", "orangish", "red"), colvar = data$Month, colkey = list(at=c(five,six,7,eight,9), labels=c("May", "jun", "jul", "Aug", "Sep"), side=one))                #Another example used rgl                x= data$Temp y=data$Ozone z=data$Solar.R rgl_init() #liat function di net rgl.spheres(x, y, z, r = v, color = "yellow", size=twenty)  # Scatter plot rgl.bbox(colour = "#333377") # Add bounding box decoration   #an case using dem data read.csv("~/change your directory here/xyz_mrp") -> r x <- r$10 y <- r$y z <- r$mrpUTM1_Resample1  #using rgl plot3d(ten = x, y = y, z = z)                #create custom colour for rgl plot                myColorRamp <- office(colors, values) {  v <- (values - min(values))/diff(range(values))    x <- colorRamp(colors)(v)   rgb(x[,one], ten[,2], x[,3], maxColorValue = 255)  }                # z every bit the fourth variable                                col <- myColorRamp(c("blueish", "green","yellow", "orange", "carmine"), z) plot3d(x = x, y = y, z = z, col=col)                #another instance using plotly                as.matrix(rasterFromXYZ(r)) -> dem dim(dem) fig <- plot_ly(z = ~dem) fig <- fig %>% add_surface() fig

References:

  • http://world wide web.sthda.com/english/wiki/a-consummate-guide-to-3d-visualization-device-system-in-r-r-software-and-data-visualization
  • https://plotly.com/r/3d-surface-plots/

Source: https://irapoenya.wordpress.com/2020/10/04/rstudio-tutorial-an-intro-to-3d-plots/

Posted by: robertsonbeirch1984.blogspot.com

0 Response to "How To Draw 3d Plots In R"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel