HISTOGRAM

x1 = rnorm(1000, mean=60, sd=10)
x2 = rnorm(1000, mean=0, sd=10)
x3 = rnorm(1000, mean=30, sd=10)

# create multiple histogram
hist(x1, col='orange', xlim=c(-35, 100))
hist(x2, col='yellow', add=TRUE)
hist(x3, col='purple', add=TRUE)

BAR PLOT

x1 = rnorm(1000, mean=60, sd=10)
x2 = rnorm(1000, mean=0, sd=10)
x3 = rnorm(1000, mean=30, sd=10)

# create multiple histogram
barplot(x1, col='orange', xlim=c(-35, 100))
barplot(x2, col='yellow', add=TRUE)
barplot(x3, col='purple', add=TRUE)

PLOT

x1 = rnorm(1000, mean=60, sd=10)
x2 = rnorm(1000, mean=0, sd=10)
x3 = rnorm(1000, mean=30, sd=10)

# create multiple histogram
plot(x1, col='orange', xlim=c(-35, 100))

plot(x2, col='yellow', add=TRUE)
## Warning in plot.window(...): "add" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "add" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "add" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "add" is not a
## graphical parameter
## Warning in box(...): "add" is not a graphical parameter
## Warning in title(...): "add" is not a graphical parameter

plot(x3, col='purple', add=TRUE)
## Warning in plot.window(...): "add" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "add" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "add" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "add" is not a
## graphical parameter
## Warning in box(...): "add" is not a graphical parameter
## Warning in title(...): "add" is not a graphical parameter

BOX PLOT

# Load necessary libraries
library(grid)
library(jpeg)
library(ggplot2)

# Load the tiger background image
img_path <- "E:\\images.jpg"
img <- readJPEG(img_path)

# Generate data
x1 <- rnorm(1000, mean = 60, sd = 10)
x2 <- rnorm(1000, mean = 0, sd = 10)
x3 <- rnorm(1000, mean = 30, sd = 10)

# Combine the data into a data frame
data <- data.frame(
  Value = c(x1, x2, x3),
  Group = factor(rep(c("x1", "x2", "x3"), each = 1000))
)

# Create the ggplot box plot
p <- ggplot(data, aes(x = Group, y = Value, fill = Group)) +
  geom_boxplot() +
  scale_fill_manual(values = c("orange", "yellow", "purple")) +
  labs(title = "Box Plot of x1, x2, and x3", x = "Groups", y = "Values") +
  theme_minimal()

# Plot the background image
grid.raster(img, width = unit(1, "npc"), height = unit(1, "npc"))

# Add the box plot on top of the background
print(p, newpage = FALSE)

PIE PLOT

# Generate random data
x1 = rnorm(1000, mean=60, sd=10)
x2 = rnorm(1000, mean=0, sd=10)
x3 = rnorm(1000, mean=30, sd=10)

# Combine the data into one vector
all_data <- c(x1, x2, x3)

# Create bins
bins <- cut(all_data, breaks = 10)  # Create 10 bins

# Calculate the count of values in each bin
bin_counts <- table(bins)

# Create a pie chart
pie(bin_counts, main = "Pie Chart of Binned Data", col = rainbow(length(bin_counts)))

row

Student mark Total
1 50 100
2 70 100
3 90 100