A line graph which is also known as a line chart is a type of graph used to visualize the value of given data over a period of time.
A line chart or graph is a single line diagram that connects a series of points by drawing line segments between them corresponding to a provided data.
These points are arranged in one of their coordinate which usually the x-coordinate value and line charts are usually used in identifying the trends in data.
A line graph consists of both horizontal x-axis and vertical y-axis.
Nearly all line graphs only have positive number values hence there axes typically intersect near the bottom of the y-axis and the left end of the x-axis.
The line graph is a powerful visual tool used for finance, marketing, and other areas. It is also useful in laboratory research, weather monitoring, or any other function involving a correlation between two numerical values.
There can be two or more lines on a graph it can be used to compare values between them.
To create and run our R program in Visual Studio we must first install some tools
Now open Visual Studio on your pc and then click on Get Tools and features… inside Tools.
Now in the feature installation window check and install the following features.
For Visual Studio 2017
Contains Tools for Data Science
After this please install R tools from the following link if the above package is not installed properly from the following link.
But it is not necessary
https://docs.microsoft.com/en-us/visualstudio/rtvs/installing-r-tools-for-visual-studio
You can also install R programming tool go to the following link for better support and download the software and install it.
For Windows Users:
For Linux Users:
If you are on Linux platform then you can use this fast and easy command used in Linux which can be used to install R. The yum command is used for installing like this:
$ yum install R
For Ubuntu Linux or other Debian-related OSs, a more direct method is:
$ apt-get install r-base
Now let us start creating our R application in visual studio
Go to Files ->Project and add a new R project
This is our project structure:
Now on the top left side is a new R file (script.R) where we can edit source code with all of Visual Studio Ide editing features.
Also on the bottom left of Visual Studio is where you can find an R Interactive window in which you can interactively develop and test code.
We can directly use R Interactive without the need of opening any new project.
The plot() function in R is used to create the line graph.
The following represents basic syntax for Line Graph −
plot(v, type, col, xlab, ylab)
Where
- v :It is a vector containing the numeric values.
- type :It takes the value “p” to draw the points of the graph while “l” to draw only the lines and “o” to draw both points and lines.
- xlab :It is the label for x axis.
- ylab :It is the label for y axis.
- main :It is the Title of the chart.
- col :It is used to give colours to both the points and lines.
Following is the code and output for Single Line Graph:
#Inserting the data into the data frame
v <- c(7,12,28,3,41)
# Plot the bar chart.
plot(v,type = “o”, col = “red”, xlab = “Month”, ylab = “Rain fall”,
main = “Rain fall chart”)
# Give the chart file a name.
png(file = “line_chart_label_colored.jpg”)
# Save the file.
dev.off()
Output:
Also let us see a demonstration for Multi Lines in a Line Graph:
# Create the data for the chart.
v <- c(7,12,28,3,41)
t <- c(14,7,6,19,3)
# Plot the bar chart.
plot(v,type = “o”,col = “red”, xlab = “Month”, ylab = “Rain fall”,
main = “Rain fall chart”)
lines(t, type = “o”, col = “blue”)
# Give the chart file a name.
png(file = “line_chart_2_lines.jpg”)
# Save the file.
dev.off()
Output:
Syllabus of Data Science training in Mumbai