library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
auto<-read.csv("Automobile.csv")
auto %>%
group_by(origin) %>%
summarise(rata_acc = mean(acceleration, na.rm = TRUE)) %>%
arrange(desc(rata_acc))
## # A tibble: 3 × 2
## origin rata_acc
## <chr> <dbl>
## 1 europe 16.8
## 2 japan 16.2
## 3 usa 15.0
auto%>%
select(-weight,-mpg)%>%
head(15)
## name cylinders displacement horsepower acceleration
## 1 chevrolet chevelle malibu 8 307 130 12.0
## 2 buick skylark 320 8 350 165 11.5
## 3 plymouth satellite 8 318 150 11.0
## 4 amc rebel sst 8 304 150 12.0
## 5 ford torino 8 302 140 10.5
## 6 ford galaxie 500 8 429 198 10.0
## 7 chevrolet impala 8 454 220 9.0
## 8 plymouth fury iii 8 440 215 8.5
## 9 pontiac catalina 8 455 225 10.0
## 10 amc ambassador dpl 8 390 190 8.5
## 11 dodge challenger se 8 383 170 10.0
## 12 plymouth 'cuda 340 8 340 160 8.0
## 13 chevrolet monte carlo 8 400 150 9.5
## 14 buick estate wagon (sw) 8 455 225 10.0
## 15 toyota corona mark ii 4 113 95 15.0
## model_year origin
## 1 70 usa
## 2 70 usa
## 3 70 usa
## 4 70 usa
## 5 70 usa
## 6 70 usa
## 7 70 usa
## 8 70 usa
## 9 70 usa
## 10 70 usa
## 11 70 usa
## 12 70 usa
## 13 70 usa
## 14 70 usa
## 15 70 japan
auto %>%
group_by(cylinders)%>%
summarise(avgMPG=mean(weight))
## # A tibble: 5 × 2
## cylinders avgMPG
## <int> <dbl>
## 1 3 2398.
## 2 4 2308.
## 3 5 3103.
## 4 6 3198.
## 5 8 4115.
ggplot(auto, aes(x = weight, y = horsepower)) +
geom_point() +
labs(title = "Weight dan Horsepower",
x = "Weight",
y = "Horsepower")
## Warning: Removed 6 rows containing missing values or values outside the scale range
## (`geom_point()`).
##2
ggplot(auto, aes(x = factor(cylinders), y = acceleration, fill=origin)) +
geom_boxplot() +
scale_fill_brewer(palette = "Dark2")+
labs(x = "Number of Cylinders", y = "Acceleration") +
ggtitle("Cylinders and Acceleration") +
theme_minimal()
options(repr.plot.width=16, repr.plot.height=8)
auto %>%
ggplot(aes(x = weight , y = displacement)) +
geom_point(aes(color = horsepower, size = acceleration), alpha = 0.7) +
scale_size_continuous(range = c(1, 8)) +
scale_color_gradient(low = "blue", high = "red") +
theme_bw() +
labs(x = "Weight", y = "Displacement", title = "Bubble Plot of Weight vs. Displacement", color = "Horsepower", size = "Acceleration",
subtitle = "Scatter Plot", caption = "Automobile Dataset") +
theme(panel.border = element_rect(color = "blue"))