data("airquality")
mean(airquality$Ozone, na.rm = TRUE)
## [1] 42.12931
median(airquality$Ozone, na.rm = TRUE)
## [1] 31.5
sd(airquality$Ozone, na.rm = TRUE)
## [1] 32.98788
plot(airquality$Wind, airquality$Temp,
main = "Scatter plot",
xlab = "Wind",
ylab = "Temp",
pch = 19,
col = "black")
data("mtcars")
library(ggplot2)
cyl_count <- as.data.frame(table(mtcars$cyl))
colnames(cyl_count) <- c("cyl", "count")
ggplot(cyl_count, aes(x = factor(cyl), y = count)) +
geom_bar(stat = "identity", fill = "black") + geom_text(aes(label = count), vjust = -0.5, size = 5) + labs(title = "Jumlah Mobil Berdasarkan Jumlah Silinder",
x = "Jumlah Silinder (cyl)",
y = "Jumlah Mobil") +
theme_minimal()
data("iris")
boxplot(Petal.Width ~ Species, data = iris,
main = "Boxplot petal.width berdasarkan species",
xlab = "petal.width",
ylab = "species",
col = "white")
korelasi <- cor(iris$Sepal.Length, iris$Petal.Length)
Setelah di uji menggunakan korelasi, 0.8717 ini menunjukkan bahwa terdapat hubungan positif antara sepal.length dan petal.length
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point(size = 3) + geom_smooth(method = "lm", se = FALSE) + labs(title = "Scatter Plot",
x = "Sepal Length",
y = "Sepal Width") +
theme_minimal() + # Tema minimalis
scale_color_manual(values = c("setosa" = "red",
"versicolor" = "yellow",
"virginica" = "green"))
## `geom_smooth()` using formula = 'y ~ x'
chisq.test(mtcars$vs,mtcars$am)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mtcars$vs and mtcars$am
## X-squared = 0.34754, df = 1, p-value = 0.5555
lm(Temp ~ Solar.R, data = airquality)
##
## Call:
## lm(formula = Temp ~ Solar.R, data = airquality)
##
## Coefficients:
## (Intercept) Solar.R
## 72.86301 0.02825
summary(lm(Temp ~ Solar.R, data = airquality))
##
## Call:
## lm(formula = Temp ~ Solar.R, data = airquality)
##
## Residuals:
## Min 1Q Median 3Q Max
## -22.3787 -4.9572 0.8932 5.9111 18.4013
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 72.863012 1.693951 43.014 < 2e-16 ***
## Solar.R 0.028255 0.008205 3.444 0.000752 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.898 on 144 degrees of freedom
## (7 observations deleted due to missingness)
## Multiple R-squared: 0.07609, Adjusted R-squared: 0.06967
## F-statistic: 11.86 on 1 and 144 DF, p-value: 0.0007518
ggplot(airquality, aes(x = Solar.R, y = Temp)) +
geom_point(color = "black", size = 2) + geom_smooth(method = "lm", col = "black") + labs(title = "Scatter Plot",
x = "Solar Radiation (Solar.R)",
y = "Temperature (Temp)") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 7 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 7 rows containing missing values or values outside the scale range
## (`geom_point()`).