R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot. # ——————————- # 1. Install & Load Packages # ——————————- install.packages(c( “tidyverse”, # For data manipulation and visualization “skimr”, # For quick data summary “DataExplorer”,# For automated EDA “ggplot2”, # For custom plots “dplyr”, # For data manipulation “readr” # For reading data ))

Load libraries

library(tidyverse) library(skimr) library(DataExplorer) library(ggplot2) library(dplyr) library(readr)

——————————-

2. Load the Dataset

——————————-

Assume you have the dataset CSV. If not, you can download it.

(Example path: “data/breast_cancer_data.csv”)

Read the dataset

Read the data

df <-read.csv(“C:/Users/DELL/Downloads/data.csv”) df <-select(df,-id,-X)

View first few rows

head(df)

Remove id and X

df <-select(df,-id,-X)

View dataset structure

str(df)

Summary statistics

summary(df)

Skim for quick summary

skimr::skim(df)

——————————-

3. Data Cleaning (Initial)

——————————-

Check for missing values

colSums(is.na(df))

Convert ‘diagnosis’ into factor if it’s not already

df\(diagnosis <- as.factor(df\)diagnosis)

Check levels

levels(df$diagnosis)

——————————-

4. Exploratory Data Analysis (EDA)

——————————-

4.1 Diagnosis distribution

ggplot(df, aes(x = diagnosis, fill = diagnosis)) + geom_bar() + labs(title = “Diagnosis Distribution”, x = “Diagnosis”, y = “Count”) + theme_minimal()

4.2 Histograms for few features (Example: radius_mean)

1. radius_mean

ggplot(df, aes(x = radius_mean, fill = diagnosis)) + geom_histogram(alpha = 0.6, bins = 30, position = ‘identity’) + labs(title = “Distribution of Radius Mean”, x = “Radius Mean”, y = “Frequency”) + theme_minimal()

2. texture_mean

ggplot(df, aes(x = texture_mean, fill = diagnosis)) + geom_histogram(alpha = 0.6, bins = 30, position = ‘identity’) + labs(title = “Distribution of Texture Mean”, x = “Texture Mean”, y = “Frequency”) + theme_minimal()

3. perimeter_mean

ggplot(df, aes(x = perimeter_mean, fill = diagnosis)) + geom_histogram(alpha = 0.6, bins = 30, position = ‘identity’) + labs(title = “Distribution of Perimeter Mean”, x = “Perimeter Mean”, y = “Frequency”) + theme_minimal()

4. area_mean

ggplot(df, aes(x = area_mean, fill = diagnosis)) + geom_histogram(alpha = 0.6, bins = 30, position = ‘identity’) + labs(title = “Distribution of Area Mean”, x = “Area Mean”, y = “Frequency”) + theme_minimal()

5. concavity_mean

ggplot(df, aes(x = concavity_mean, fill = diagnosis)) + geom_histogram(alpha = 0.6, bins = 30, position = ‘identity’) + labs(title = “Distribution of Concavity Mean”, x = “Concavity Mean”, y = “Frequency”) + theme_minimal()

4.3 Boxplot of a feature by diagnosis

ggplot(df, aes(x = diagnosis, y = radius_mean, fill = diagnosis)) + geom_boxplot() + labs(title = “Radius Mean by Diagnosis”, x = “Diagnosis”, y = “Radius Mean”) + theme_minimal()

OR

library(tidyverse)

Select the features you want to plot

important_features <- df %>% select(diagnosis, radius_mean, texture_mean, perimeter_mean, area_mean, concavity_mean)

Reshape data from wide to long format

long_df <- important_features %>% pivot_longer(cols = -diagnosis, names_to = “Feature”, values_to = “Value”)

Plot

ggplot(long_df, aes(x = Value, fill = diagnosis)) + geom_histogram(alpha = 0.6, bins = 30, position = ‘identity’) + facet_wrap(~ Feature, scales = “free”, ncol = 2) + labs( title = “Distribution of Important Features by Diagnosis”, x = “Value”, y = “Frequency”, fill = “Diagnosis” ) + scale_fill_manual(values = c(“B” = “skyblue”, “M” = “red”)) + theme_minimal(base_size = 14)

4.4 Pairwise Scatter Plot (Optional for small datasets)

Select few variables

selected_vars <- df %>% select(diagnosis, radius_mean, texture_mean, perimeter_mean, area_mean, smoothness_mean)

GGally::ggpairs (optional package for nice pair plots)

install.packages(“GGally”)

library(GGally)

ggpairs(selected_vars, aes(color = diagnosis))

——————————-

5. Quick Automated EDA Report (Optional)

——————————-

Create a fast EDA report in HTML

create_report(df) # Uncomment if you want a full automated EDA report (DataExplorer)