##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")
gss<-read.csv("GSSsubset.csv")
ggplot(gss, aes(x = age, y = income)) +
geom_point(color = "blue") +
labs(title = "Income vs Age", x = "Age", y = "Income") +
theme_minimal()
ggplot(gss, aes(x = sex)) +
geom_bar(fill = "green") +
labs(title = "Gender Distribution", x = "Gender", y = "Count") +
theme_classic()
ggplot(gss, aes(x = income)) +
geom_histogram(binwidth = 10000, fill = "orange", color = "black") +
labs(title = "Income Distribution", x = "Income", y = "Frequency") +
theme_light()
ggplot(gss, aes(x = sex, y = income)) +
geom_boxplot(fill = "purple") +
labs(title = "Income by Gender", x = "Gender", y = "Income") +
theme_bw()
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()
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)