-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssigment 3 solution.R
46 lines (35 loc) · 1.5 KB
/
Assigment 3 solution.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#Question 1
library(ggplot2)
data(iris)
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, color=Species)) +
geom_point()
#Question 2
data(txhousing)
sum(is.na(txhousing))
txhousing <- txhousing[complete.cases(txhousing), ]
ggplot(txhousing, aes(sales)) +
geom_histogram()
ggplot(txhousing, aes(median)) +
geom_histogram()
ggplot(txhousing, aes(sales, median)) +
geom_point()
ggplot(txhousing, aes(city, sales)) +
geom_boxplot()
ggplot(txhousing, aes(city, median)) +
geom_boxplot()
str(txhousing)
summary(txhousing)
plot(txhousing$year, txhousing$median, main = "Median House Value over Time", xlab = "Year", ylab = "Median House Value")
barplot(table(txhousing$year), main = "Number of Houses by Year", xlab = "Year", ylab = "Count")
boxplot(median ~ year, data = txhousing, main = "Median House Value by Year", xlab = "Year", ylab = "Median House Value")
hist(txhousing$median, main = "Median House Value Distribution", xlab = "Median House Value")
plot(txhousing$inventory, txhousing$median, main = "Median House Value vs. Square Footage", xlab = "Square Footage", ylab = "Median House Value")
#Question 3
titanic <- read.csv("titanic.csv")
titanic$Survived <- ifelse(titanic$Survived == 0, "dead", "survived")
final_Plot = ggplot(data=titanic,aes(y=Survived ,x=Fare,fill = Sex))+
geom_boxplot(position = "dodge")+
facet_grid(Survived ~ ., scales = "free_y", space = "free_y") +
labs(x = "Fare", y = "", title = "Titanic") +
theme_minimal()
final_Plot