You are on page 1of 4

WORKSHEET 5

Tiya Bhattacharya

Ans1) plot(mpg,hp)

mpg <- c(21, 22, 18, 16, 17, 15, 14, 14, 12, 19)

hp <- c(110, 95, 123, 180, 150, 200, 210, 215, 225, 100)

xlab=mpg

ylab=hp

main="mtcars data"

col="rainbow"
Ans2) data <- data.frame(species, sepal_length)

avg_sepal_length <- tapply(data$sepal_length, data$species, mean)

barplot(avg_sepal_length, names.arg = species,main = "Average Sepal Length by Species",xlab =


"Species",ylab = "Average Sepal Length",col = "pink")
Ans3) Diet <- c("A", "B", "A", "B", "A", "B", "A", "B", "A", "B")

Time <- c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2)

Weight <- c(40, 45, 60, 55, 50, 65, 70, 75, 80, 85)

data <- data.frame(Diet, Time, Weight)

library(ggplot2)

ggplot(data, aes(x = Time, y = Weight, fill = Diet)) +

geom_boxplot() +

labs(

title = "Weight Distribution of Chicks by Diet and Time",

x = "Time",

y = "Weight",

fill = "Diet"

)+

scale_fill_manual(values = c("A" = "blue" ="green"))


Ans4) um_bins <- 5

eruptions <- c(3.6, 1.8, 3.333, 2.283, 4.533, 2.883, 4.7, 3.6, 1.95, 4.35)

hist(eruptions, breaks = num_bins,smain = "Histogram of Eruption Durations", xlab = "Eruption


Duration", ylab = "Frequency",col = "purple")

You might also like