Slip No.13
1) Consider the inbuilt iris dataseti) Create a variable “y” and attach to it the output attribute of the “iris” dataset.
ii) Create a barplot to breakdown your output attribute.
iii) Create a density plot matrix for each attribute by class value.
1. Open RStudio.
2. Create a New Script:
Go to File > New File > R Script, or press Ctrl + Shift + N (Windows).
3. Type these code in the Script:
# Load necessary libraries
library(ggplot2)
library(GGally)
# Load the iris dataset
data(iris)
# Create a variable "y" with the output attribute (Species)
y <- iris$Species
# Create a barplot for the output attribute
barplot(table(y),
main = "Distribution of Iris Species",
xlab = "Species",
ylab = "Frequency",
col = c("lightblue", "lightgreen", "lightpink"))
# Create a density plot matrix
ggpairs(iris,aes(color = Species, fill = Species),title = "Density Plot Matrix of Iris Attributes")
Save the script by going to File > Save, or press Ctrl + S (Windows). Name the file something like array_operations.R.
5. Run the Script:
You can run the script by clicking the Source button at the top of the script editor, or by selecting the entire script and pressing Ctrl + Enter (Windows).
No comments:
Post a Comment