How to Plot in 3D clusters using plotly package Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report R-Language is widely used in Data Science, Data Visualization Data Analysis many more, etc. Plotly package is highly rich in plotting various graphs, These graphs/charts are highly interactive and user-friendly. The 3D cluster visualizes the similarity between variables as 3-D spatial relationships. Each point in the graph represents an individual property. the points which are closer together were more frequently sorted into the same category or class. Using Example: Plotting the following dataset in 3-D plot using plotly library in R Programming Language.x y z 1 10 2 2 20 4 3 30 8 4 40 16 5 50 32 Syntax: plot_ly(data_object, x, y, z) where: data_object: Represents the dataset or dataframe object.x : Represent x-data vector.y : Represent y-data vector.z : Represent z-data vector. Example 1: In this example, we will create an exemplary dataset and then plot a 3D Cluster graph using that. R #Importing plotly library library(plotly) #Creating Dataframe x = c(1, 2, 3, 4, 5) y = c(10, 20, 30, 40, 50) z = c(2, 4, 8, 16, 32) df = data.frame(x, y, z) df #Plotting 3-D Scatter plot. #Pass dataframe and axes plt <- plot_ly(df, x = ~x, y = ~y, z = ~z) #Add markers to the chart plt <- plt %>% add_markers() #Labeling the axes. plt <- plt %>% layout(scene = list(xaxis = list(title = 'x-axis'), yaxis = list(title = 'y-axis'), zaxis = list(title = 'z-axis'))) plt Output: Example 2: In this example, we will use the iris dataset and then plot it with the original labels using any three independent features. R #Importing Library library(plotly) #Using iris dataset #Removing Categorical Values data = iris[, 1:4] #Finding Clusters data$cluster = factor(kmeans(data, 3)$cluster) #Plotting the Data clust<- plot_ly(data, x=~Sepal.Length, y=~Sepal.Width, z=~Petal.Width, color=~cluster) %>% add_markers(size=1.5) #Printing 3-D Clusters clust Output: Comment More infoAdvertise with us Next Article Stacked bar plot Using Plotly package in R D dhanushrajsrmq47 Follow Improve Article Tags : Technical Scripter R Language Technical Scripter 2022 Similar Reads Stacked bar plot Using Plotly package in R In general, the bar plots are used to plot the categorical data. The stacked bar plot is a type of bar plot which is used to visualize the data effectively in the same bar by plotting them in a stacked manner. These are mostly used when one wants to summarize similar kinds of data by plotting a sing 4 min read How to Create Pie Chart Using Plotly in R The pie chart is a circular graphical representation of data that is divided into some slices based on the proportion of it present in the dataset. In R programming this pie chart can be drawn using Plot_ly() function which is present in the Plotly package. In this article, we are going to plot a pi 3 min read How to Create an Animated Line Graph using Plotly An animated line graph is a visual representation of data that changes over time or over a categorical variable. It can be a powerful tool for visualizing trends and patterns in data and can help to communicate complex ideas in a clear and concise way. In this tutorial, we will learn how to create a 5 min read How to do 3D line plots grouped by two factors with the Plotly package in R? Plotly is a powerful library for making interactive charts. We will be able to plot 3D line plots using Plotly that can be utilized to analyze complex data and display results in a clear manner.Syntax: plot_ly(data, x = ~x, y = ~y, z = ~z, type = "scatter3d", mode = "lines")Parameters:data: The data 3 min read Choropleth Maps using Plotly in Python Plotly is a Python library that is very popular among data scientists to create interactive data visualizations. One of the visualizations available in Plotly is Choropleth Maps.  Choropleth maps are used to plot maps with shaded or patterned areas which are proportional to a statistical variable. T 3 min read Create a Choropleth Map by using Plotly Package in R There are plenty of packages in R that can be used to make maps, like leaflet, mapview, ggplot, spplot, plotly, etc. Each of the packages has its own advantages and disadvantages. But all of them have the common goal of making it easy to create maps and visualize geospatial data. In this article, we 4 min read Like