Add p.value in GGplot with linear Models

CMBSI <- lm(BSI_GSI_mzp2_T ~ ctq_sum, data = Datamed_cleanpair)
summary(CMBSI)

windows()
ggplot(Datamed_cleanpair, aes(x = ctq_sum, y = BSI_GSI_mzp2_T)) +
geom_point() +
geom_smooth(method = lm, se = TRUE, fullrange = TRUE) +
xlab('CM-Load') +
ylab('GSI Score') +
geom_text(label = paste("R² = ", round(summary(CMBSI)$r.squared, 2)), x = 10, y = 5)

I get a scatterplot but the R² is not in the image and I would like to add the p.value as well.

I expect it would only run without error, and not show the R2 if x=10,y=5 were not within the plotting region. are they ?

1 Like

yes ! Can I add the p.value like this

windows()
ggplot(Datamed_cleanpair, aes(x = ctq_sum, y = BSI_GSI_mzp2_T)) +
geom_point() +
geom_smooth(method = lm, se = TRUE, fullrange = TRUE) +
xlab('CM-Load') +
ylab('GSI Score') +
geom_text(label = paste("R² = ", round(summary(CMBSI)$r.squared, 2)), x = 80, y = 30)+
geom_text(label = paste("p = ", round(summary(CMBSI)$p.value, 2)), x = 80, y = 35)

Yes, and it works when I put the x and y higher. But its kind of thick and not very pretty.
I woud like to have it also in the same row.
Are there different ways to but values in a graphic or do i need to do this with Excel ?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.