Initial commit
This commit is contained in:
98
plot1/plot.R
Normal file
98
plot1/plot.R
Normal file
@@ -0,0 +1,98 @@
|
||||
library(ggplot2)
|
||||
library(readr)
|
||||
library(latex2exp)
|
||||
|
||||
data_t1 <- read_csv(
|
||||
"m1,m2,a_measured
|
||||
0.055,0.060,0.380
|
||||
0.060,0.065,0.354
|
||||
0.065,0.070,0.323
|
||||
0.070,0.075,0.310
|
||||
0.075,0.080,0.303
|
||||
0.080,0.085,0.279
|
||||
0.065,0.075,0.649
|
||||
0.080,0.095,0.780"
|
||||
)
|
||||
|
||||
a_theoretical <- function(m) {
|
||||
9.81 * m
|
||||
}
|
||||
|
||||
m_from_masses <- function(m1, m2) {
|
||||
(m2 - m1) / (m1 + m2)
|
||||
}
|
||||
|
||||
x_lab <- function() {
|
||||
TeX(r"($M$)")
|
||||
}
|
||||
|
||||
y_lab <- function() {
|
||||
TeX(r"($a \ \small{m \cdot s^{-2}}$)")
|
||||
}
|
||||
|
||||
lm_eqn <- function(df) {
|
||||
m <- lm(df)
|
||||
eq <- substitute(
|
||||
italic(y) == a + b %.% italic(x),
|
||||
list(a = format(unname(coef(m)[1]), digits = 3),
|
||||
b = format(unname(coef(m)[2]), digits = 3))
|
||||
)
|
||||
as.character(as.expression(eq))
|
||||
}
|
||||
|
||||
data_t1["M"] <- m_from_masses(data_t1["m1"], data_t1["m2"])
|
||||
|
||||
data_t1["a"] <- data_t1$M * 9.8
|
||||
|
||||
plt <- ggplot(
|
||||
data = data_t1,
|
||||
mapping = aes(x = M, y = a_measured)
|
||||
) +
|
||||
geom_point(
|
||||
col = "#D55E00",
|
||||
size = 2,
|
||||
) +
|
||||
geom_smooth(
|
||||
se = FALSE,
|
||||
method = "lm",
|
||||
linewidth = 0.8,
|
||||
col = "#D55E00",
|
||||
) +
|
||||
theme(
|
||||
axis.text = element_text(size = 14),
|
||||
axis.title = element_text(size = 20),
|
||||
) +
|
||||
labs(
|
||||
x = x_lab(),
|
||||
y = y_lab(),
|
||||
) +
|
||||
annotate("text",
|
||||
label = lm_eqn(data_t1[, c("a_measured", "M")]),
|
||||
x = 0.076,
|
||||
y = 0.58,
|
||||
size = 5,
|
||||
col = "#D55E00",
|
||||
parse = TRUE,
|
||||
) +
|
||||
annotate("segment",
|
||||
x = min(data_t1$M),
|
||||
y = a_theoretical(min(data_t1$M)),
|
||||
xend = max(data_t1$M),
|
||||
yend = a_theoretical(max(data_t1$M)),
|
||||
linewidth = 0.8,
|
||||
col = "#0072B2",
|
||||
) +
|
||||
annotate("text",
|
||||
label = "Theoretical",
|
||||
x = 0.068,
|
||||
y = 0.74,
|
||||
col = "#0072B2",
|
||||
size = 5,
|
||||
)
|
||||
|
||||
plt
|
||||
|
||||
ggsave("plot.pdf",
|
||||
plot = plt,
|
||||
device = cairo_pdf,
|
||||
)
|
||||
Reference in New Issue
Block a user