R - Charts and Graphs
R - Charts and Graphs
Graphs
R – graphs
• A line graph is a chart that is used to display information in the form of a series of data points.
• Syntax: plot(v, type, col, xlab, ylab)
•
Parameters:
• v: This parameter is a contains only the numeric values
• type: This parameter has the following value:
• “p” : This value is used to draw only the points.
• “l” : This value is used to draw only the lines.
• “o”: This value is used to draw both points and lines
• xlab: This parameter is the label for x axis in the chart.
• ylab: This parameter is the label for y axis in the chart.
• main: This parameter main is the title of the chart.
• col: This parameter is used to give colors to both the points and lines.
example
# Create the data for the chart.
v <- c(17, 25, 38, 13, 41)
# Plot the line chart.
plot(v, type = "o")
where:
barplot( A, col=color_name)
• # defining vector
• x <- c(7, 15, 23, 12, 28, 56, 64)
• # plotting vector
• barplot(x, xlab = “ bar plot example",
• ylab = “ ", col = “orange",
• col.axis = “red",
• col.lab = “red")
• where,
• x is data vector
• labels shows names given to slices
• col fills the color in the slices as given parameter
• main shows title name of the pie chart
• radius indicates radius of the pie chart. It can be between -1 to +1
• # Create data for the graph.
• x<- c(23, 56, 20, 63)
• labels <- c("Mumbai", "Pune", "Chennai", "Bangalore")
• # plotting
• plot(x = orange$age, y = orange$circumference, xlab = "Age",
ylab = "Circumference", main = "Age VS Circumference",
col.lab = "darkgreen", col.main = "darkgreen",
col.axis = "darkgreen")
Box plot shows how the data is distributed in the data vector.
It represents five values in the graph i.e., minimum, first quartile, second quartile(median), third quartile,
the maximum value of the data vector.
• # plotting
• boxplot(x, xlab = "Box Plot", ylab = "Age",
• col.axis = "darkgreen", col.lab = "darkgreen")