Hey everyone. I am brand new to R and to this community, so I apologize if I make formatting mistakes in this question, and for how easy this problem would be to solve for most of you.
I am doing a few linear regressions for a project. I waived the white flag on getting R to produce the equation on the graph in ggplot, so I am now opting to add a line of best fit with geom_smooth
and then manually adding my R2 values calculated in Excel. My ultimate goal is to display four different graphs on one grid, each with the R2 value in the graph. I have accomplished the first part of that using Plot_grid
, but have only managed to get the R2 values as subtitles underneath each graph rather than inside of them.
Here is the best example of me getting the R2 in an individual graph:
Caption <- TeX("$R^{2}$ = 0.56")
Byrd.Reg <- ggplot(Byrd,aes(x=Observed, y=Counter)) +
geom_point(shape = 1) +
geom_smooth(method='lm', se = FALSE)+
theme_classic()+
labs(title = "Byrd House", caption = (Caption) )
ggdraw(add_sub(Byrd.Reg, (Caption), vpadding=grid::unit(0, "lines"),
y = 15, x = 0.1, hjust = 0))
Byrd.Reg
This sort of works, except it produces two different graphs, one with the product of ggdraw
and one without. Later, which I use Plot_grid
it seems to plot the version without the ggdraw
function.
I would love to understand what I am doing that makes R produce two graphs here, and how I can fix it so that I have only one which is incorporated into my Plot_grid
function later.
Thanks!