library(readr)
library(ggplot2)
#Finding and loading Life Expectancy data from www.kaggle.com
df <- read_csv('Life Expectancy Data.csv',
col_select = c("Year", "Life_expectancy"))
## Rows: 2848 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (2): Year, Life_expectancy
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
summary(df)
## Year Life_expectancy
## Min. :2000 Min. :39.40
## 1st Qu.:2004 1st Qu.:62.90
## Median :2008 Median :71.45
## Mean :2008 Mean :68.95
## 3rd Qu.:2011 3rd Qu.:75.50
## Max. :2015 Max. :83.80
#Viewing Missing Values
print(paste("There are", sum(is.na(df$Life_expectancy)), "missing values in this dataset."))
## [1] "There are 0 missing values in this dataset."
# Plot the selected data using color codes
plot <- ggplot(data = df, aes(x = Year, y = Life_expectancy, color = Life_expectancy))+
geom_point(size = 2, alpha = 0.8)+
scale_color_gradient(name = "Age", low = "#47BEFB", high = "#ED6AA8")+
ggtitle("Life Expectancy Over Year from 2000 to 2015")+
xlab("Year")+
ylab("Age")
# Adjust font sizes
plot + theme(
text = element_text(size = 12), # Overall text size
axis.title = element_text(size = 14, face = "italic"), # Axis titles with italic face
axis.text = element_text(size = 10), # Axis labels
plot.title = element_text(size = 16, face = "bold") # Plot title with bold face
)
Preattentive attributes determine what information catches audience attention. This is important in visualization because it enables us to direct our people attention towards the most important information in our visual.So, Choosing the right color, fonts and type of visualization make the data visuliztion clear, informative, and beautiful.