Gyan Ganga Institute of Technology & Sciences, Jabalpur
Lab Manual
CS-605 (Data Analytics Lab)
Name : ………………………………………….
Roll No. : ………………………………………….
Class : CSE Sixth Semester (Batch- )
Department of Computer Science and Engineering
2024-2025
Exp. No. AIM Date Sign.
1 Perform various mathematical operations in
python.
2 Perform various operations on matrix in python.
3 Perform various statistical operations in python.
4 Demonstrate Data Visualization in python.
5 Write the steps to install R language.
6 Perform creation of variables, data type, numbers,
strings and mathematical operations in R.
7 Perform branching and looping statements in R.
8 Use of Vector, List, Metrics and Array in R.
9 Demonstrate Data Visualization in R.
10 Study of MATLAB commands.
11 Design a Dashboard in Power Bi
Certificate(s) Completed
INDEX
Experiment No. 1
Aim: Perform various mathematical operations in python.
Basic Mathematics Operations:
Operator Name Example
+ Addition x +y
- Subtraction x -y
* Multiplication x *y
/ Division x /y
% Modulus x %y
** Exponentiation x ** y
// Floor division x // y
x=7
y=3
result = x+y
print(result)
10
result = x-y
print(result)
4
result = x*y
print(result)
21
result = x/y
print(result)
2.3333333333333335
result = x%y
print(result)
1
result = x**y
print(result)
343
result = x//y
print(result)
2
Some Built-in Math Functions:
The min() and max() functions can be used to find the lowest or highest value in an iterable:
a = min(5, 15, 10)
print(a)
5
a = min(5, 15, 10)
print(a)
15
The abs() function returns the absolute (positive) value of the specified number:
a = abs(-7.25)
7.25
The pow(x, y) function returns the value of x power y means (xy).
a = pow(5, 2)
print(a)
25
The Math Module
Python has also a built-in module called math, which extends the list of mathematical functions.
To use it, you must import the math module:
import math
When you have imported the math module, you can start using methods and constants of the
module.
The math.sqrt() method for example, returns the square root of a number:
import math
x = math.sqrt(64)
print(x)
8.0
The math.ceil() method rounds a number upwards to its nearest integer and returns the result:
import math
x = math.ceil(10.5)
print(x)
11
The math.floor() method rounds a number downwards to its nearest integer and returns the
result:
import math
x = math.floor(10.5)
print(x)
10
The math.pi constant, returns the value of PI (3.14...):
import math
x = math.pi
print(x)
3.141592653589793
Experiment No. 2
Aim: Perform various operations on matrix in python.
NumPy is a Python package. It stands for 'Numerical Python'. It is a library consisting of
multidimensional array objects and a collection of routines for processing of array. Using
NumPy, mathematical and logical operations on arrays can be performed.
Import Numpy −
import numpy
Operation on Matrix:
1. add() :- This function is used to perform element wise matrix addition.
2. subtract() :- This function is used to perform element wise matrix subtraction.
3. divide() :- This function is used to perform element wise matrix division.
# Python code to demonstrate matrix operations
# add(), subtract() and divide()
# importing numpy for matrix operations
import numpy
# initializing matrices
x = numpy.array([[1, 2], [4, 5]])
y = numpy.array([[7, 8], [9, 10]])
# using add() to add matrices
print ("The element wise addition of matrix is : ")
print (numpy.add(x,y))
The element wise addition of matrix is :
[[ 8 10]
[13 15]]
# using subtract() to subtract matrices
print ("The element wise subtraction of matrix is : ")
print (numpy.subtract(x,y))
The element wise subtraction of matrix is :
[[-6 -6]
[-5 -5]]
# using divide() to divide matrices
print ("The element wise division of matrix is : ")
print (numpy.divide(x,y))
The element wise division of matrix is :
[[ 0.14285714 0.25 ]
[ 0.44444444 0.5 ]]
4. multiply() :- This function is used to perform element wise matrix multiplication.
5. dot() :- This function is used to compute the matrix multiplication, rather than element
wise multiplication.
# Python code to demonstrate matrix operations
# multiply() and dot()
# importing numpy for matrix operations
import numpy
# initializing matrices
x = numpy.array([[1, 2], [4, 5]])
y = numpy.array([[7, 8], [9, 10]])
# using multiply() to multiply matrices element wise
print ("The element wise multiplication of matrix is : ")
print (numpy.multiply(x,y))
The element wise multiplication of matrix is :
[[ 7 16]
[36 50]]
# using dot() to multiply matrices
print ("The product of matrices is : ")
print (numpy.dot(x,y))
The product of matrices is :
[[25 28]
[73 82]]
6. sqrt() :- This function is used to compute the square root of each element of matrix.
7. sum(x,axis) :- This function is used to add all the elements in matrix. Optional “axis”
argument computes the column sum if axis is 0 and row sum if axis is 1.
8. “T” :- This argument is used to transpose the specified matrix.
# Python code to demonstrate matrix operations
# sqrt(), sum() and "T"
# importing numpy for matrix operations
import numpy
# initializing matrices
x = numpy.array([[1, 2], [4, 5]])
y = numpy.array([[7, 8], [9, 10]])
# using sqrt() to print the square root of matrix
print ("The element wise square root is : ")
print (numpy.sqrt(x))
The element wise square root is :
[[ 1. 1.41421356]
[ 2. 2.23606798]]
# using sum() to print summation of all elements of matrix
print ("The summation of all matrix element is : ")
print (numpy.sum(y))
The summation of all matrix element is :
34
# using sum(axis=0) print summation of each column of matrix
print ("The column wise summation of all matrix is : ")
print (numpy.sum(y,axis=0))
The column wise summation of all matrix is :
[16 18]
# using sum(axis=1) print summation of each row of matrix
print ("The row wise summation of all matrix is : ")
print (numpy.sum(y,axis=1))
The row wise summation of all matrix is :
[15 19]
# using "T" to transpose the matrix
print ("The transpose of given matrix is : ")
print (x.T)
The transpose of given matrix is :
[[1 4]
[2 5]]
Experiment No. 3
Aim: Perform various statistical operations in python.
Statistics, in general, is the method of collection of data, tabulation, and interpretation of
numerical data. It is an area of applied mathematics concerned with data collection analysis,
interpretation, and presentation.
Measure of Central Tendency
The measure of central tendency is a single value that attempts to describe the whole set of
data. There are three main features of central tendency:
• Mean
• Median
• Median Low
• Median High
• Mode
Mean
The Mean Value is the Average of all values.
Mean(x)= ∑x / n
import statistics
s = [1, 3, 3, 4, 5, 7]
x = statistics.mean(s)
print(x)
89.76923076923077
Median
The Median Value is the value in the Middle of all values.
For Odd Numbers:
(n+1) / 2
For Even Numbers:
(n/2+(n/2+1))/2
import statistics
s = [99,86,87,88,111,86,103,87,94,78,77,85,86]
x = statistics.median(s)
print(x)
87.0
import statistics
set = [1, 3, 3, 4, 5, 7]
x = statistics.median(set)
y= statistics.median_low(set)
z= statistics.median_high(set)
print(x)
print(y)
print(z)
3.5
3
4
Mode
The Mode Value is the value that appears the most number of times.
import statistics
sp = [2, 3, 3, 4, 5, 5, 5, 5, 6, 6, 6, 7]
x = statistics.mode(sp)
print(x)
import statistics
na = ["red", "blue", "black", "blue", "black", "black", "brown"]
x = statistics.mode(na)
print(x)
black
Measure of Variability
The measure of variability is known as the spread of data or how well our data is distributed.
The most common variability measures are:
• Range
• Variance
• Standard deviation
Range
The difference between the largest and smallest data point in our data set is known as the
range.
arr = [1, 2, 3, 4, 5]
#Finding Max
Maximum = max(arr)
# Finding Min
Minimum = min(arr)
# Difference of Max and Min
Range = Maximum-Minimum
print("Maximum = {}, Minimum ={} and Range ={} ".format(Maximum, Minimum, Range))
Maximum = 5, Minimum =1 and Range =4
Variance
It is defined as an average squared deviation from the mean.
Where N = number of terms and µ is mean.
importstatistics
s = [1, 2, 5, 4, 8, 9, 12]
x = statistics.variance(s)
print(x)
15.80952380952381
Standard Deviation
It is defined as the square root of the variance.
Where N = number of terms and µ is mean.
importstatistics
s = [1, 2, 5, 4, 8, 9, 12]
x = statistics.stdev(s)
print(x)
3.9761191895520196
Experiment No. 4
Aim: Demonstrate Data Visualization in python
To create data sets, the Python module NumPy is used, which comes with a number of methods
to create random data sets of any size.
For example, an array containing 50 random floats between 0 and 5 are created as:
import numpy
x = numpy.random.uniform(0.0, 5.0, 50)
print(x)
[4.94207564 4.23563063 2.52021663 2.39936219 4.82161559 0.38759736
0.9698932 0.68561456 1.11441435 1.05373901 0.73291293 0.82123575
4.58906592 2.63719998 3.42701459 1.12471662 4.8715162 1.63893489
3.68363035 1.2386152 3.54621978 1.84935346 4.87183921 0.77364862
4.87006048 3.37716311 2.1696595 3.09555608 0.69324266 3.54138191
0.05924744 3.25472033 3.86161533 1.41689779 2.64550167 3.70527096
4.71196797 0.02633703 4.4620886 4.98808643 0.14150763 4.76594866
3.64562571 4.88304668 1.35961059 2.00379659 3.42392412
0.762792861.99939105 0.9116701 ]
Histogram
To visualize the data set, we can draw a histogram with random distributed data.We will use the
Python module Matplotlib to draw a histogram.
import numpy
import matplotlib.pyplot as plt
x = numpy.random.uniform(0.0, 5.0, 50)
plt.hist(x, 5)
plt.show()
Explanation of Histogram is that 4 values in array are between 0 and 1, 14 values in array are
between 1 and 2, 7 values in array are between 2 and 3, 14 values in array are between 3 and 4,
11 values in array are between 4 and 5.
We can also draw a histogram with normaldatadistribution.
import numpy
import matplotlib.pyplot as plt
x = numpy.random.normal(5.0, 1.0, 10000)
plt.hist(x, 100)
plt.show()
We use the array from the numpy.random.normal() method, with 10000 values, to draw a
histogram with 100 bars.We specify that the mean value is 5.0, and the standard deviation is 1.0.
Line Plot
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
plt.plot(x, y)
plt.title("Sports Watch Data")
plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")
plt.show()
Line Plot with Grid
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
plt.title("Sports Watch Data")
plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")
plt.plot(x, y)
plt.grid()
plt.show()
Scatter Plot
A scatter plot is a diagram where each value in the data set is represented by a dot.
The Matplotlib module has a method for drawing scatter plots, it needs two arrays of the same
length, one for the values of the x-axis, and one for the values of the y-axis:
import matplotlib.pyplot as plt
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
plt.scatter(x, y)
plt.title("Scatter Plot")
plt.xlabel("Age of Car")
plt.ylabel("Speed")
plt.show()
where, the x array represents the age of each car and the y array represents the speed of each car.
Bar Plot
It is also possible to plot Bar Chart instead of Scatter plot by replacing plt.scatter(x,y)with
plt.bar(x,y)as:
import matplotlib.pyplot as plt
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
plt.bar(x, y)
plt.title("Bar Chart")
plt.xlabel("Age of Car")
plt.ylabel("Speed")
plt.show()
Horizontal Bar Plot
import matplotlib.pyplot as plt
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
plt.barh(x, y)
plt.title("Bar Chart")
plt.xlabel("Age of Car")
plt.ylabel("Speed")
plt.show()
Pie Plot
import matplotlib.pyplot as plt
import numpy as np
y = np.array([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
plt.pie(y, labels = mylabels)
plt.legend()
plt.show()
Experiment No. 5
Aim:Write the steps to install R language.
What is R?
R is a popular programming language used for statistical computing and graphical presentation.
Its most common use is to analyze and visualize data.
Why Use R?
It is a great resource for data analysis, data visualization, data science and machine
learning
It provides many statistical techniques (such as statistical tests, classification, clustering
and data reduction)
It is easy to draw graphs in R, like pie charts, histograms, box plot, scatter plot, etc++
It works on different platforms (Windows, Mac, Linux)
It is open-source and free
It has a large community support
It has many packages (libraries of functions) that can be used to solve different problems
Installation of R language:
Enter “R Cran” in google search, choose the first link appearing in the screen CRAN - R Project
Then following page appeared on the screen:
Select Download R for Windows link, and clik over the install R for first time link appearing in
the next page.
Now click on Download R-4.5.0 for Windows link, so it will download and then we install it by
selecting YES option from setup wizard.
After completion the R Console is open on the screen.
Now to install R with IDE, we enter “R Studio” in google search, choose the first link appearing
in the screen RStudio Desktop
Now click over the “DOWNLOAD RSTUDIO DESKTOP FOR WINDOWS” in the next page,
it will download the Rstudio and we will install it.
Now we will open by selecting RStudio in our System as:
So, Rstudio will appeared on over screen and ready to implement R functions and expressions
etc.
Experiment No. 6
Aim: Perform creation of variables, data type, numbers, strings and mathematical operations in
R.
Creating Variables in R
Variables are containers for storing data values. R does not have a command for declaring a variable.
A variable is created the moment you first assign a value to it. To assign a value to a variable, use
the < - sign.
> name <- "John"
> age <- 40
> name # output "John"
[1] "John"
> age # output 40
[1] 40
R does have a print() function, to output variables.
> name <- "John Doe"
> print(name) # print the value of the name variable
[1] "John Doe"
Concatenate Elements
You can also concatenate, or join, two or more elements, by using the paste() function. To
combine both text and a variable, R uses comma (,):
> text <- "awesome"
> paste("R is", text)
[1] "R is awesome"
> text1 <- "R is"
> text2 <- "awesome"
> paste(text1, text2)
[1] "R is awesome"
Multiple Variables
R allows you to assign the same value to multiple variables in one line:
# Assign the same value to multiple variables in one line
> var1 <- var2 <- var3 <- "Orange"
# Print variable values
> var1
[1] "Orange"
> var2
[1] "Orange"
> var3
[1] "Orange"
Basic Data Types
Basic data types in R can be divided into the following types:
numeric - (10.5, 55, 787)
integer - (1L, 55L, 100L, where the letter "L" declares this as an integer)
complex - (9 + 3i, where "i" is the imaginary part)
character (a.k.a. string) - ("k", "R is exciting", "FALSE", "11.5")
logical (a.k.a. boolean) - (TRUE or FALSE)
We can use the class( ) function to check the data type of a variable:
# numeric
> x <- 10.5
> class(x)
[1] "numeric"
# integer
> x <- 1000L
> class(x)
[1] "integer"
# complex
> x <- 9i + 3
> class(x)
[1] "complex"
# character/string
> x <- "R is exciting"
> class(x)
[1] "character"
# logical/boolean
> x <- TRUE
> class(x)
[1] "logical"
Numbers
There are three number types in R:
numeric
integer
complex
Variables of number types are created when you assign a value to them:
> x <- 10.5 # numeric
> class(x)
[1] "numeric""integer"
> y <- 10L # integer
> class(y)
[1] "integer"
> z <- 1i # complex
> class(y)
[1] "complex"
String Literals
Strings are used for storing text. A string is surrounded by either single quotation marks, or
double quotation marks: "hello" is the same as 'hello'
If you want the line breaks to be inserted at the same position as in the code, use
the cat() function:
> str <- "Lorem ipsum dolor sit amet,
consectetur adipiscing elit"
> cat(str)
Lorem ipsum dolor sit amet,
consectetur adipiscing elit
String Length
to find the number of characters in a string, use the nchar() function:
> str <- "Hello World!"
> nchar(str)
[1] 12
Combine Two Strings
Use the paste() function to merge/concatenate two strings:
> str1 <- "Hello"
> str2 <- "World"
> paste(str1, str2)
[1] “Hello World”
R Math
In R, you can use operators to perform common mathematical operations on numbers.
> 10 + 5
[1] 15
> 10 * 5
[1] 50
Some Built-in Math Function
The min( ) and max( ) functions can be used to find the lowest or highest number in a set:
> max(5, 10, 15)
[1] 15
> min(5, 10, 15)
[1] 5
The sqrt( ) function returns the square root of a number:
> sqrt(16)
[1] 4
The abs( ) function returns the absolute (positive) value of a number:
> abs(-6.5)
[1] 6.5
The ceiling( ) function rounds a number upwards to its nearest integer, and the floor( ) function
rounds a number downwards to its nearest integer, and returns the result:
> ceiling(1.4)
[1] 2
> floor(1.4)
[1] 1
Experiment No. 7
Aim: Perform branching and looping statements in R.
The if Statement
An "if statement" is written with if keyword and it is used to specify a block of code to be
executed if a condition is TRUE:
a <- 33
b <- 200
if (b > a) {
print("b is greater than a")
}
[1] "b is greater than a"
Else If
a <- 33
b <- 33
if (b > a) {
print("b is greater than a")
} else if (a == b) {
print ("a and b are equal")
}
[1] "a and b are equal"
If Else
The else keyword catches anything which isn't caught by the preceding conditions:
a <- 200
b <- 33
if (b > a) {
print("b is greater than a")
} else if (a == b) {
print("a and b are equal")
} else {
print("a is greater than b")
}
[1] "a is greater than b"
Nested If Statements
You can also have if statements inside if statements, this is called nested if statements.
x <- 41
if (x > 10) {
print("Above ten")
if (x > 20) {
print("and also above 20!")
} else {
print("but not above 20.")
}
} else {
print("below 10.")
}
[1] "Above ten"
[1] "and also above 20!"
Loops
Loops can execute a block of code as long as a specified condition is reached.
R has two loop commands:
while loops
for loops
R While Loops
With the while loop we can execute a set of statements as long as a condition is TRUE:
i <- 1
while (i < 6) {
print(i)
i <- i + 1
}
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
R For Loop
A for loop is used for iterating over a sequence:
for (x in 1:5) {
print(x)
}
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
fruits <- list("apple", "banana", "cherry")
for (x in fruits) {
print(x)
}
[1] "apple"
[1] "banana"
[1] "cherry"
dice <- c(1, 2, 3, 4, 5, 6)
for (x in dice) {
print(x)
}
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
Nested Loops
It is also possible to place a loop inside another loop. This is called a nested loop:
adj <- list("red", "big", "tasty")
fruits <- list("apple", "banana", "cherry")
for (x in adj) {
for (y in fruits) {
print(paste(x, y))
}
}
[1] "red apple"
[1] "red banana"
[1] "red cherry"
[1] "big apple"
[1] "big banana"
[1] "big cherry"
[1] "tasty apple"
[1] "tasty banana"
[1] "tasty cherry"
Experiment No. 8
Aim: Use of Vector, List, Metrics and Array in R.
R Vectors
A vector is simply a list of items that are of the same type. To combine the list of items to a
vector, use the c() function and separate the items by a comma.
# Vector of strings
fruits <- c("banana", "apple", "orange")
# Print fruits
fruits
[1] "banana" "apple" "orange"
# Vector of numerical values
numbers <- c(1, 2, 3)
# Print numbers
numbers
[1] 1 2 3
# Vector with numerical values in a sequence
numbers <- 1:5
numbers
[1] 1 2 3 4 5
R Lists
A list in R can contain many different data types inside it. A list is a collection of data which is
ordered and changeable.
To create a list, use the list( ) function:
# List of strings
thislist <- list("apple", "banana", "cherry")
# Print the list
thislist
[[1]]
[1] "apple"
[[2]]
[1] "banana"
[[3]]
[1] "cherry"
Access List Item
thislist[1]
[[1]]
[1] "apple"
Change List Item
thislist[1] <- "blackcurrant"
thislist
[[1]]
[1] "blackcurrant"
[[2]]
[1] "banana"
[[3]]
[1] "cherry"
Add List Item
append(thislist, "orange")
thislist
[[1]]
[1] "blackcurrant"
[[2]]
[1] "banana"
[[3]]
[1] "cherry"
[[4]]
[1] "orange"
Add List Item after specific position
append(thislist, "greps", after = 2)
thislist
[[1]]
[1] "blackcurrant"
[[2]]
[1] "banana"
[[3]]
[1] "greps"
[[4]]
[1] "cherry"
[[5]]
[1] "orange"
Remove List Item
newlist <- thislist[-1]
newlist
[[1]]
[1] "banana"
[[2]]
[1] "greps"
[[3]]
[1] "cherry"
[[4]]
[1] "orange"
Remove List
list1 <- list("a", "b", "c")
list2 <- list(1,2,3)
list3 <- c(list1,list2)
list3
[[1]]
[1] "a"
[[2]]
[1] "b"
[[3]]
[1] "c"
[[4]]
[1] 1
[[5]]
[1] 2
[[6]]
[1] 3
R Matrices
A matrix is a two dimensional data set with columns and rows. A matrix can be created with
the matrix( ) function. Specify the nrow and ncol parameters to get the amount of rows and
columns:
# Create a matrix
thismatrix <- matrix(c(1,2,3,4,5,6), nrow = 3, ncol = 2)
# Print the matrix
thismatrix
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
thismatrix <- matrix(c("apple", "banana", "cherry", "orange"), nrow
= 2, ncol = 2)
thismatrix
[,1] [,2]
[1,] "apple" "cherry"
[2,] "banana" "orange
thismatrix[1, 2]
[1] "cherry"
thismatrix[2,]
[1] "banana" "orange"
thismatrix[,2]
[1] "cherry" "orange"
R Arrays
Compared to matrices, arrays can have more than two dimensions. We use the array( ) function
to create an array, and the dim parameter to specify the dimensions:
# An array with one dimension with values ranging from 1 to 24
thisarray <- c(1:24)
thisarray
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# An array with more than one dimension
multiarray <- array(thisarray, dim = c(4, 3, 2))
multiarray
,,1
[,1] [,2] [,3]
[1,] 1 5 9
[2,] 2 6 10
[3,] 3 7 11
[4,] 4 8 12
,,2
[,1] [,2] [,3]
[1,] 13 17 21
[2,] 14 18 22
[3,] 15 19 23
[4,] 16 20 24
Experiment No. 9
Aim: Demonstrate Data Visualization in R.
R Plots
x <- c(1, 2, 3, 4, 5)
y <- c(3, 7, 8, 9, 12)
plot(x, y)
Scatter Plots
A "scatter plot" is a type of plot used to display the relationship between two numerical
variables, and plots one dot for each observation. It needs two vectors of same length, one for the
x-axis (horizontal) and one for the y-axis (vertical):
x <- c(5,7,8,7,2,2,9,4,11,12,9,6)
y <- c(99,86,87,88,111,103,87,94,78,77,85,86)
plot(x, y, main="Observation of Cars", xlab="Car age", ylab="Car
speed")
Compare Plots
# day one, the age and speed of 12 cars:
x1 <- c(5,7,8,7,2,2,9,4,11,12,9,6)
y1 <- c(99,86,87,88,111,103,87,94,78,77,85,86)
# day two, the age and speed of 15 cars:
x2 <- c(2,2,8,1,15,8,12,9,7,3,11,4,7,14,12)
y2 <- c(100,105,84,105,90,99,90,95,94,100,79,112,91,80,85)
plot(x1, y1, main="Observation of Cars", xlab="Car age", ylab="Car
speed", col="red", cex=2)
points(x2, y2, col="blue", cex=2)
Line Graphs
A line graph has a line that connects all the points in a diagram.
plot(1:10, type="l", col="blue", lwd=2)
Multiple Lines
To display more than one line, use the plot( ) function together with the lines( ) function:
line1 <- c(1,2,3,4,5,10)
line2 <- c(2,5,7,8,9,10)
plot(line1, type = "l", col = "blue")
lines(line2, type="l", col = "red")
Bar Charts
A bar chart uses rectangular bars to visualize data. Bar charts can be displayed horizontally or
vertically. The height or length of the bars are proportional to the values they represent. Use
the barplot( ) function to draw a vertical bar chart:
# x-axis values
x <- c("A", "B", "C", "D")
# y-axis values
y <- c(2, 4, 6, 8)
barplot(y, names.arg = x, col = "red")
Horizontal Bars
If you want the bars to be displayed horizontally instead of vertically, use horiz = TRUE:
x <- c("A", "B", "C", "D")
y <- c(2, 4, 6, 8)
barplot(y, names.arg = x, col = "red", horiz = TRUE)
Pie Chart
# Create a vector of labels
mylabel <- c("Apples", "Bananas", "Cherries", "Dates")
# Create a vector of colors
colors <- c("blue", "yellow", "green", "black")
# Display the pie chart with colors
pie(x, label = mylabel, main = "Pie Chart", col = colors)
# Display the explanation box
legend("bottomright", mylabel, fill = colors)
Experiment No. 10
Aim: Study of MATLAB commands.
MATLAB (matrix laboratory) is a fourth-generation high-level programming language and
interactive environment for numerical computation, visualization and programming. MATLAB
is developed by MathWorks.
Features of MATLAB
Following are the basic features of MATLAB −
It is a high-level language for numerical computation, visualization and application
development.
It also provides an interactive environment for iterative exploration, design and problem
solving.
It provides vast library of mathematical functions for linear algebra, statistics, Fourier
analysis, filtering, optimization, numerical integration and solving ordinary differential
equations.
It provides built-in graphics for visualizing data and tools for creating custom plots.
MATLAB's programming interface gives development tools for improving code quality
maintainability and maximizing performance.
It provides tools for building applications with custom graphical interfaces.
It provides functions for integrating MATLAB based algorithms with external
applications and languages such as C, Java, .NET and Microsoft Excel.
Uses of MATLAB
MATLAB is widely used as a computational tool in science and engineering encompassing the
fields of physics, chemistry, math and all engineering streams. It is used in a range of
applications including −
Signal Processing and Communications
Image and Video Processing
Control Systems
Test and Measurement
Computational Finance
Computational Biology
Commands for Managing a Session
MATLAB provides various commands for managing a session. The following table provides all
such commands −
Command Purpose
clc Clears command window.
clear Removes variables from memory.
exist Checks for existence of file or variable.
global Declares variables to be global.
lookfor Searches help entries for a keyword.
quit Stops MATLAB.
who Lists current variables.
Commands for Working with the System:
Command Purpose
cd Changes current directory.
date Displays current date.
delete Deletes a file.
diary Switches on/off diary file recording.
dir Lists all files in current directory.
load Loads workspace variables from a file.
path Displays search path.
pwd Displays current directory.
save Saves workspace variables in a file.
type Displays contents of a file.
what Lists all MATLAB files in the current directory.
Vector, Matrix and Array Commands:
Command Purpose
cat Concatenates arrays.
find Finds indices of nonzero elements.
length Computes number of elements.
linspace Creates regularly spaced vector.
logspace Creates logarithmically spaced vector.
max Returns largest element.
min Returns smallest element.
prod Product of each column.
reshape Changes size.
size Computes array size.
sort Sorts each column.
sum Sums each column.
eye Creates an identity matrix.
ones Creates an array of ones.
zeros Creates an array of zeros.
cross Computes matrix cross products.
dot Computes matrix dot products.
det Computes determinant of an array.
inv Computes inverse of a matrix.
Experiment No. 11
Aim: Design a Dashboard in Power Bi.
Consider a Excel file “Sales”, Which contain sales of furniture products year wise.
Year Chair Table Almirah Sofa
2021 1000 530 621 251
2022 989 514 617 241
2023 1156 568 635 287
2024 1234 614 687 305
Now open Power BI Desktop and click on Blank Report:
Then in the appearing window click on “Import data from Excel”
Then select “Sales” Excel file and on Navigator Panel select the Sheet(s) to be loaded and then click over
LOAD button, it can load the excel sheet(s) in Power BI Desktop. After this following Window appears in
screen:
On clicking over “Table View” in Left Panel, we can view the loaded table(s):
Now by clicking on “Report View”, we return back to Report View to create graph(s) on dashboard.
First we create a line graph by selecting it from Visualization panel, so it will appear in dashboard as:
Now select fields from Data Panel and Drag & Drop in X-axis and Y-axis area of Visualization panel.
On Clicking over so a popup menu will appear, then we select “Rename
for this visual” and change the “Sum of Almirah” by “Almirah”, Similarly other fields of Y-axis are also
changed.
Now by clicking on “Format your Visual” in Visualization Panel, we set “Visual” Properties like Legands,
Values etc. and from “General” we set Title of this Graph. Immediate effect of these will reflect on our
Graph in Dashboard.
Now we select a “Clustered Column Chart” and Set X-Axis as Year and Y-Axis As Chair and Sofa.
Now we select “Clustered Bar Chart” and set X-Axis as Year and Y-Axis As Almirah and Chair.
Finally, we select “Donut Chart” and set Legand and Values as Table.