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

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

Build a Multi ClassText Classification Model using Naive Bayes
Implement the Naive Bayes Algorithm to build a multi class text classification model in Python.

Azure Deep Learning-Deploy RNN CNN models for TimeSeries
In this Azure MLOps Project, you will learn to perform docker-based deployment of RNN and CNN Models for Time Series Forecasting on Azure Cloud.

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

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.

Image Classification Model using Transfer Learning in PyTorch
In this PyTorch Project, you will build an image classification model in PyTorch using the ResNet pre-trained model.

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

Build a Credit Default Risk Prediction Model with LightGBM
In this Machine Learning Project, you will build a classification model for default prediction with LightGBM.

MLOps Project on GCP using Kubeflow for Model Deployment
MLOps using Kubeflow on GCP - Build and deploy a deep learning model on Google Cloud Platform using Kubeflow pipelines in Python

Deep Learning Project for Text Detection in Images using Python
CV2 Text Detection Code for Images using Python -Build a CRNN deep learning model to predict the single-line text in a given image.

OSZAR »