Professional Documents
Culture Documents
Assignment
Assignment
Assignment
Assignment 2
Question 1: Make a basic histogram using the age data from the Titanic data set using
ggplot.
Answer:
Code:
titanic_data %>%
ggplot(aes(x = Age, fill = Survived)) +
geom_histogram() +
theme_classic() + theme(
plot.title = element_text(family = "Times New Roman", hjust = 0.5), axis.text =
element_text(family = "Times New Roman",face = "bold"), axis.title =
element_text(family = "Times New Roman", face = "bold"),
legend.title = element_blank(),
legend.text = element_text(family = "Times New Roman")
)+
labs(title = "Survival rates by Age")
Question 3: The ‘cars’ data set gives the speed of cars and the distances
taken to stop. Note that the data were recorded in the 1920s. Plot the
‘cars’ data set as a scatter plot.
Answer:
Code:
library(ggplot2)
Output:
Question 5: Explain the steps of reading and writing into a CSV file.
Answer:
Syntax:
write.csv(data, path) Parameter:
data: data to be added to csv
path: pathname of the file
Approach:
Create a DataFrame
Pass required values to the function
Write to file
Save the file