This is an R Markdown web page presentation. In this web page, plotly package shall be used to display graphs in 3D.
2 February 2018
This is an R Markdown web page presentation. In this web page, plotly package shall be used to display graphs in 3D.
iris dataset used for plotting
predictors : Sepal Length, Sepal Width, Petal length, Petal Width
Response : Species - factors of levels: setosa, versicol, virginica
library(caret) library(plotly) library(ggplot2) library(dplyr) summary(iris) intrain <- createDataPartition(y=iris$Species, p = 0.70,list=FALSE) training <- iris[intrain,] testing <- iris[-intrain, ] plot(x=iris$Sepal.Length, y=iris$Sepal.Width, col=iris$Species) modelfit <- train(Species~., data=iris, method="rf") modelfit predOut <- predict(modelfit, newdata=testing[, -5]) predOut confusionMatrix(predOut, testing$Species)
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:stats': ## ## filter
## The following object is masked from 'package:graphics': ## ## layout
library(ggplot2)
plot_ly(x=iris$Sepal.Length, y=iris$Sepal.Width, z=iris$Petal.Length, color=as.factor(iris$Species), mode="markers", type="scatter3d", showlegend=TRUE)