How to add slider and range selectors to chart using plotly in R

This recipe helps you add slider and range selectors to chart using plotly in R

Recipe Objective

How to add slider and range selectors to a chart using plotly ?

The sliders and range selectors are input features in plotly which help users to control the interactivity in a plot. The user can select a value between the stated minimum and maximum range. Input boxes are also provided for the users to manually enter the required values. This recipe demonstrates an example on how to add slider and range selectors to a chart using plotly.

Step 1 - Install the necessary library

install.packages("plotly") library(plotly)

Step 2 - Define a Dataframe

data <- data.frame(x = c(10,20,30,40,50,60,70,80,90,100), y = c(2,9,7,8,10,5,3,6,7,3))

Step 3 - Use sliders for charts

steps <- list( list(args = list("marker.color", "blue"), label = "Blue_col", method = "restyle", value = "1" ), list(args = list("marker.color", "purple"), label = "Purple_col", method = "restyle", value = "2" ), list(args = list("marker.color", "orange"), label = "Orange_col", method = "restyle", value = "3" ) ) figure <- data figure <- figure %>% plot_ly(x = ~x, y = ~y, mode = "markers", marker = list(size = 40, color = 'green'), type = "scatter") figure <- figure %>% layout(title = "Slider_Plots", sliders = list( list( active = 1, currentvalue = list(prefix = "Color: "), pad = list(t = 40), steps = steps))) figure {"mode":"full","isActive":false}

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Credit Card Default Prediction using Machine learning techniques
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Recommender System Machine Learning Project for Beginners-2
Recommender System Machine Learning Project for Beginners Part 2- Learn how to build a recommender system for market basket analysis using association rule mining.

Recommender System Machine Learning Project for Beginners-3
Content Based Recommender System Project - Building a Content-Based Product Recommender App with Streamlit

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Skip Gram Model Python Implementation for Word Embeddings
Skip-Gram Model word2vec Example -Learn how to implement the skip gram algorithm in NLP for word embeddings on a set of documents.

CycleGAN Implementation for Image-To-Image Translation
In this GAN Deep Learning Project, you will learn how to build an image to image translation model in PyTorch with Cycle GAN.

Llama2 Project for MetaData Generation using FAISS and RAGs
In this LLM Llama2 Project, you will automate metadata generation using Llama2, RAGs, and AWS to reduce manual efforts.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.