##1.install and load library

#Load the library
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3

##working directory

setwd("~/R TRAININIG")

Import the dataset

gss<-read.csv("GSSsubset.csv") 

Example: Scatter plot of ‘income’ vs ‘age’

ggplot(gss, aes(x = age, y = income)) +
  geom_point(color = "blue") +
  labs(title = "Income vs Age", x = "Age", y = "Income") +
  theme_minimal()

Example: Bar plot of ‘gender’ counts

ggplot(gss, aes(x = sex)) +
  geom_bar(fill = "green") +
  labs(title = "Gender Distribution", x = "Gender", y = "Count") +
  theme_classic()

Example: Histogram of ‘income’

ggplot(gss, aes(x = income)) +
  geom_histogram(binwidth = 10000, fill = "orange", color = "black") +
  labs(title = "Income Distribution", x = "Income", y = "Frequency") +
  theme_light()

Example: Boxplot of ‘income’ by ‘gender’

ggplot(gss, aes(x = sex, y = income)) +
  geom_boxplot(fill = "purple") +
  labs(title = "Income by Gender", x = "Gender", y = "Income") +
  theme_bw()

Example: Scatter plot with customizations

ggplot(gss, aes(x = age, y = income, color = sex)) +
  geom_point(size = 3) +
  labs(title = "Income vs Age by Gender",
       x = "Age (years)",
       y = "Income ($)",
       color = "Gender") +
  theme_minimal()

## Example: Scatter plot with a dark theme

ggplot(gss, aes(x = age, y = income)) +
  geom_point(color = "tomato") +
  labs(title = "Income vs Age", 
       x = "Age", 
       y = "Income") +
  theme_classic()

Example: Scatter plot with customized colors and sizes

ggplot(gss, aes(x = age, y = income, color = sex, size = income)) +
  geom_point(alpha = 0.6) +
  scale_color_manual(values = c("red", "blue")) +
  labs(title = "Income vs Age by Gender", x = "Age", y = "Income") +
  theme_classic()

##library (ggplot2)