#Slice Percentage & Chart Legend Program:
# Create data for the graph.
geeks <- c(23, 56, 20, 63)
labels <- c("Mumbai", "Pune", "Chennai", "Bangalore")
piepercent<- round(100 * geeks / sum(geeks), 1)
# Plot the chart.
pie(geeks, labels = piepercent,
main = "City pie chart", col = rainbow(length(geeks)))
legend("topright", c("Mumbai", "Pune", "Chennai", "Bangalore"),
cex = 0.5, fill = rainbow(length(geeks)))
#3D Pie Chart Program:
# Get the library.
library(plotrix)
# Create data for the graph.
geeks <- c(23, 56, 20, 63)
labels <- c("Mumbai", "Pune", "Chennai", "Bangalore")
piepercent<- round(100 * geeks / sum(geeks), 1)
# Plot the chart.
pie3D(geeks, labels = piepercent,
main = "City pie chart", col = rainbow(length(geeks)))
legend("topright", c("Mumbai", "Pune", "Chennai", "Bangalore"),
cex = 0.5, fill = rainbow(length(geeks)))
##Boxplots
#Creating a Dataset Program:
input <- mtcars[, c('mpg', 'cyl')]
print(head(input))
#Creating the Boxplot Program:
# Plot the chart.
boxplot(mpg ~ cyl, data = mtcars,
xlab = "Number of Cylinders",
ylab = "Miles Per Gallon",
main = "Mileage Data")
##Multiple Boxplot program:
set.seed(20000)
data <- data.frame( A = rpois(900, 3),
B = rnorm(900),
C = runif(900)
)
# Applying boxplot function
boxplot(data)
##Boxplot using notch Program:
# Plot the chart.
boxplot(mpg ~ cyl, data = mtcars,
xlab = "Number of Cylinders",
ylab = "Miles Per Gallon",
main = "Mileage Data",
notch = TRUE,
varwidth = TRUE,
col = c("green", "red", "blue"),
names = c("High", "Medium", "Low")
)
#bar charts Program:
data(chickwts) #loading data into workspace
plot(chickwts$feed) # plot feed from chickwts
feeds=table(chickwts$feed)
# plots graph in decreasing order
barplot(feeds[order(feeds, decreasing=TRUE)])
feeds = table(chickwts$feed)
# outside margins bottom, left, top, right.
par(oma=c(1, 1, 1, 1))
par(mar=c(4, 5, 2, 1))
# las is used orientation of axis labels
barplot(feeds[order(feeds, decreasing=TRUE)]
# horiz is used for bars to be shown as horizontal.
barplot(feeds[order(feeds)], horiz=TRUE,
# col is used for colouring bars.
# xlab is used to label x-axis.
xlab="Number of chicks", las=1 col="yellow")
##Pie charts Program:
data("chickwts")
# main is used to create
# an heading for the chart
d = table(chickwts$feed)
pie(d[order(d, decreasing=TRUE)],
clockwise=TRUE,
main="Pie Chart of feeds from chichwits", )
To embed this program on your website, copy the following code and paste it into your website's HTML: