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

Build a Multi Touch Attribution Model in Python with Source Code

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

Syntax:

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

where,

  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')

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

Build Portfolio Optimization Machine Learning Models in R
Machine Learning Project for Financial Risk Modelling and Portfolio Optimization with R- Build a machine learning model in R to develop a strategy for building a portfolio for maximized returns.

AWS MLOps Project to Deploy Multiple Linear Regression Model
Build and Deploy a Multiple Linear Regression Model in Python on AWS

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

Build Regression Models in Python for House Price Prediction
In this Machine Learning Regression project, you will build and evaluate various regression models in Python for house price prediction.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

FEAST Feature Store Example for Scaling Machine Learning
FEAST Feature Store Example- Learn to use FEAST Feature Store to manage, store, and discover features for customer churn prediction machine learning project.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data