- This slide displays the core R code used to reproduce the analysis of Kepler’s Third Law. It shows how the Solar System data are created, transformed into logarithmic form, and modeled using simple linear regression. -The final lines use ggplot2 to visualize the relationship between log(T) (orbital period) and log(R) (AU), producing the log–log plot seen earlier.
# Build data
planets <- tibble::tibble(
name = c("Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"),
distance_AU = c(0.39, 0.72, 1.00, 1.52, 5.20, 9.58, 19.18, 30.07),
orbital_period_days = c(88, 225, 365, 687, 4333, 10759, 30687, 60190)
)
# Transform + fit model
df <- planets %>% mutate(logT = log10(orbital_period_days),
logR = log10(distance_AU))
m <- lm(logT ~ logR, data = df)
# Visualize
ggplot(df, aes(logR, logT)) +
geom_point() +
geom_smooth(method = "lm")