Skip to content

Commit 2ac55ac

Browse files
committed
Added model equation.
Centered title and equation. Changed theme to default.
1 parent 6872e30 commit 2ac55ac

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ server <- function(input, output) {
4343
p <- ggplot(plot_data, aes(x = charge, y = speed)) +
4444
geom_point() +
4545
labs(x = "Charge (kg)", y = "Speed (m/s)", title = "Load-velocity Model") +
46-
theme_minimal()
46+
theme(plot.title = element_text(hjust = 0.5)) # Center the plot title
4747

4848
if(nrow(plot_data) > 1) {
4949
fit <- lm(speed ~ charge, data = plot_data)
5050
p <- p + geom_smooth(method = "lm", col = "blue", se = FALSE, formula = 'y ~ x')
51+
52+
# Add the regression equation to the plot
53+
eq <- paste0("y = ", round(coef(fit)[1], 4), " + ", round(coef(fit)[2], 4), "x")
54+
p <- p + annotate("text", x = mean(plot_data$charge), y = max(plot_data$speed), label = eq, size = 4, color = "blue")
5155
}
5256

5357
ggplotly(p)

0 commit comments

Comments
 (0)