How to plot a simple x and y chart in R?

How to plot a simple x and y chart in R?

How to plot a simple x and y chart in R?

This recipe helps you plot a simple x and y chart in R


Recipe Objective

Scatter plot is the simplest chart which uses cartesian coordinates to display the relation between two variables x and y. It is used to find any trend between the two variables.

This recipe demonstrates how to plot a simple x,y chart in R

STEP 1: Creating Example data

We will use an example of no of schools established in 2 states between 1970 and 2014

# years year_x = c('1970','1980', '1990', '2000', '2013', '2014') ​ ​ #no of schools in state1 corresponding to a particular year state_y1 = c(15, 30, 60, 120, 240, 300)

STEP 2: Plotting a basic scatter chart with multiple points on the graph

Using plot() function to plot the number of schools vs Year for a state


plot(X, y, type, col, main, xlab, ylab)


  1. X = x values
  2. Y = y values
  3. col = colour of the line
  4. main = title of the graph
  5. xlab = xlabel of the plot
  6. ylab = ylabel of the plot
plot(year_x, state_y1, col = 'red', main = 'Number of schools vs Year', xlab = 'Year', ylab = 'Number of Schools')

Relevant Projects

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

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.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

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.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

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.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.