R Plots
R Plots
1. pie(X, Labels, Radius, Main, Col, Clockwise)
X is a vector that contains the numeric values used in the pie chart.
Labels are used to give the description to the slices.
Radius describes the radius of the pie chart.
Main describes the title of the chart.
Col defines the color palette.
Clockwise is a logical value that indicates the clockwise or anti-clockwise
direction in which slices are drawn.
# Creating data for the graph.
x <- c(20, 65, 15, 50)
labels <- c("India", "America", "Shri Lanka", "Nepal")
# Giving the chart file a name.
png(file = "Country.jpg")
# Plotting the chart.
pie(x,labels)
# Saving the file.
dev.off()
pie(x,labels,main="Country Pie chart",col=rainbow(length(x)))
legend(x,y=NULL,legend,fill,col,bg)
R Bar Charts
barplot(h,x,y,main, names.arg,col)
H A vector or matrix which contains numeric values used in the bar chart.
xlab A label for the x-axis.
ylab A label for the y-axis.
main A title of the bar chart.
names.arg A vector of names that appear under each bar.
col It is used to give colors to the bars in the graph.
# Creating the data for Bar chart
H<- c(12,35,54,3,41)
# Giving the chart file a name
png(file = "bar_chart.png")
# Plotting the bar chart
barplot(H)
# Saving the file
dev.off()
png(file = "bar_chart.png")
barplot(Values, main = "Total Revenue", names.arg = months, xlab = "Month", ylab = "Revenue", ccol
=c("cadetblue3","deeppink2","goldenrod1"))
dev.off()
R Boxplot
boxplot(x, data, notch, varwidth, names, main)
x It is a vector or a formula.
varwidth It is also a logical value set as true to draw the width of the box same as the sample size.
names It is the group of labels that will be printed under each boxplot.
# Giving a name to the chart file.
png(file = "boxplot.png")
# Plotting the chart.
boxplot(mpg ~ cyl, data = mtcars, xlab = "Quantity of Cylinders",
ylab = "Miles Per Gallon", main = "R Boxplot Example")
# Save the file.
dev.off()
R Histogram
hist(v,main,xlab,ylab,xlim,ylim,breaks,col,border)
# Creating data for the graph.
v <- c(12,24,16,38,21,13,55,17,39,10,60)
# Giving a name to the chart file.
png(file = "histogram_chart.png")
# Creating the histogram.
hist(v,xlab = "Weight",ylab="Frequency",col = "green",border = "red")
# Saving the file.
dev.off()
# Creating data for the graph.
v <- c(12,24,16,38,21,13,55,17,39,10,60,120,40,70,90)
# Giving a name to the chart file.
png(file = "histogram_return.png")
# Creating the histogram.
m<hist(v,xlab = "Weight",ylab="Frequency",col = "darkmagenta",border = "pink", break
s = 5)
#Setting labels
text(m$mids,m$counts,labels=m$counts, adj=c(0.5, -0.5))
# Saving the file.
dev.off()