Presentation
Presented
By
Momna Fatima
Reg No: 2277
Bs IT (Evening) 7th
Sem
About R Language
History of R Language
Features of R Language
Features of R Language
Reasons to Learn R Language
•How to Download R
•Installing R Studio
R Studio Window:
R – graph:
R language is mostly used for statistics and data analytics purposes to
represent the data graphically in the software. To represent those data
graphically, charts and graphs are used in R.
There are hundreds of charts and graphs present in R. For example, bar
plots, box plots, mosaic plots, dot charts, coplot, histograms, pie charts,
scatter graphs, etc.
Types of R – Charts
• Pie Diagram or Pie Chart
• Bar Plot or Bar Chart
• Histogram
• Scatter Plot
Pie Diagram or Pie Chart
The pie chart is a circular chart divided into different segments
according to the ratio of data provided. The total value of the pie
is 100 and the segments tell the fraction of the whole pie. It is
another method to represent statistical data in graphical form
and the pie() function is used to perform the same.
Syntax: pie(x, labels, col, main, radius)
where,
• x is the data vector
• labels show names given to slices
• col fills the color in the slices as the given parameter
• main shows the title name of the pie chart
Example:
# Create a vector of pies
x <- c(10,20,30,40)
# Create a vector of labels
mylabel <- c("Apples", "Bananas", "Cherries", "Dates")
# Display the pie chart with labels
pie(x, label = mylabel, main = "Fruits")
Out Put:
You can add a color to each pie with the col parameter:
# Create a vector of colors
colors<- c("blue", "yellow", "green", "black")
# Display the pie chart with colors
pie(x, label = mylabel, main = "Fruits", col = colors)
Legend
To add a list of explanations for each pie, use
the legend() function:
Example:
# 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)
The legend can be positioned as either:
bottomright, bottom, bottomleft, left, topleft, top, topright,
right, center
Out Put:
Bar Charts
A bar chart uses rectangular bars to visualize data. A bar chart
represents data in rectangular bars with the length of the bar
proportional to the value of the variable. R uses the
function barplot() to create bar charts.
Syntax: barplot(data, xlab, ylab)
where:
• data is the data vector to be represented on the y-axis
• xlab is the label given to the x-axis
• ylab is the label given to the y-axis
• names. arg defines the names of each observation in the x-
axis
Example:
x <- c(“Jan", “Feb", “March", “April")
y <- c(2, 4, 6, 8)
barplot(y,name.args = x, col = "yellow", xlab = "Month",
ylab = "Revenue", border = "red“, main = "Revenue bar
chart")
Out Put:
Histogram:
A histogram is a graphical representation used to create a graph with
bars representing the frequency of grouped data in a vector. The
histogram is the same as a bar chart, but the only difference is that it
represents the frequency of grouped data rather than the data itself.
Syntax: hist(x, col, border, main, xlab, ylab)
where:
• x is the data vector
• col specifies the color of the bars to be filled
• border specifies the color of the border of bars
• main specifies the title name of the histogram
• xlab specifies the x-axis label
• ylab specifies the y-axis label
• xlim: is used to specify the range of values on the x-axis.
• ylim: is used to specify the range of values on the y-axis.
Example:
v <- c(12, 24, 16, 38, 21, 13, 55, 17, 39, 10, 60, 59, 58)
hist(v, col = “green", xlab = “weight“ ,
ylab = “Frequency", border = "red“, main = “Frequency bar
chart“, ylim = c (0,5), xlim =c (10,60))
Out put:
Scatter plot:
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 the same length, one for the x-axis (horizontal)
and one for the y-axis (vertical).a
Syntax: plot(x, y, type, xlab, ylab, main)
Where,
• x is the data vector represented on the x-axis
• y is the data vector represented on the y-axis
• xlab specifies the label for the x-axis
• ylab specifies the label for the y-axis
• main specifies the title name of the graph
• xlim: This parameter is used for plotting values of x.
• ylim: This parameter is used for plotting values of y.
Example:
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“ , xlim = c(2,12), ylim = c(80,5 )
To recap, the observation in the example above is the result of 12 cars
passing by.
Out Put:
The x-axis shows how old the car is.
The y-axis shows the speed of the car when it passes.
Are there any relationships between the observations?
It seems that the newer the car, the faster it drives.

R programming.pptx r language easy concept

  • 1.
  • 2.
  • 3.
    History of RLanguage
  • 4.
    Features of RLanguage
  • 5.
    Features of RLanguage
  • 6.
    Reasons to LearnR Language
  • 7.
  • 8.
  • 9.
  • 10.
    R – graph: Rlanguage is mostly used for statistics and data analytics purposes to represent the data graphically in the software. To represent those data graphically, charts and graphs are used in R. There are hundreds of charts and graphs present in R. For example, bar plots, box plots, mosaic plots, dot charts, coplot, histograms, pie charts, scatter graphs, etc. Types of R – Charts • Pie Diagram or Pie Chart • Bar Plot or Bar Chart • Histogram • Scatter Plot
  • 11.
    Pie Diagram orPie Chart The pie chart is a circular chart divided into different segments according to the ratio of data provided. The total value of the pie is 100 and the segments tell the fraction of the whole pie. It is another method to represent statistical data in graphical form and the pie() function is used to perform the same. Syntax: pie(x, labels, col, main, radius) where, • x is the data vector • labels show names given to slices • col fills the color in the slices as the given parameter • main shows the title name of the pie chart Example: # Create a vector of pies x <- c(10,20,30,40) # Create a vector of labels mylabel <- c("Apples", "Bananas", "Cherries", "Dates") # Display the pie chart with labels pie(x, label = mylabel, main = "Fruits") Out Put: You can add a color to each pie with the col parameter: # Create a vector of colors colors<- c("blue", "yellow", "green", "black") # Display the pie chart with colors pie(x, label = mylabel, main = "Fruits", col = colors)
  • 12.
    Legend To add alist of explanations for each pie, use the legend() function: Example: # 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) The legend can be positioned as either: bottomright, bottom, bottomleft, left, topleft, top, topright, right, center Out Put:
  • 13.
    Bar Charts A barchart uses rectangular bars to visualize data. A bar chart represents data in rectangular bars with the length of the bar proportional to the value of the variable. R uses the function barplot() to create bar charts. Syntax: barplot(data, xlab, ylab) where: • data is the data vector to be represented on the y-axis • xlab is the label given to the x-axis • ylab is the label given to the y-axis • names. arg defines the names of each observation in the x- axis Example: x <- c(“Jan", “Feb", “March", “April") y <- c(2, 4, 6, 8) barplot(y,name.args = x, col = "yellow", xlab = "Month", ylab = "Revenue", border = "red“, main = "Revenue bar chart") Out Put:
  • 14.
    Histogram: A histogram isa graphical representation used to create a graph with bars representing the frequency of grouped data in a vector. The histogram is the same as a bar chart, but the only difference is that it represents the frequency of grouped data rather than the data itself. Syntax: hist(x, col, border, main, xlab, ylab) where: • x is the data vector • col specifies the color of the bars to be filled • border specifies the color of the border of bars • main specifies the title name of the histogram • xlab specifies the x-axis label • ylab specifies the y-axis label • xlim: is used to specify the range of values on the x-axis. • ylim: is used to specify the range of values on the y-axis. Example: v <- c(12, 24, 16, 38, 21, 13, 55, 17, 39, 10, 60, 59, 58) hist(v, col = “green", xlab = “weight“ , ylab = “Frequency", border = "red“, main = “Frequency bar chart“, ylim = c (0,5), xlim =c (10,60)) Out put:
  • 15.
    Scatter plot: A "scatterplot" 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 the same length, one for the x-axis (horizontal) and one for the y-axis (vertical).a Syntax: plot(x, y, type, xlab, ylab, main) Where, • x is the data vector represented on the x-axis • y is the data vector represented on the y-axis • xlab specifies the label for the x-axis • ylab specifies the label for the y-axis • main specifies the title name of the graph • xlim: This parameter is used for plotting values of x. • ylim: This parameter is used for plotting values of y. Example: 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“ , xlim = c(2,12), ylim = c(80,5 ) To recap, the observation in the example above is the result of 12 cars passing by. Out Put: The x-axis shows how old the car is. The y-axis shows the speed of the car when it passes. Are there any relationships between the observations? It seems that the newer the car, the faster it drives.