I am creating a scatter plot between a dependent variable FA and subject age (in yrs) that has 2 group conditions (Exercise and Rest).
I am having issues setting the regression lines so that I can have the regression line for the Exercise group be solid and the Rest group be dotted.
It seems as if ggscatter won't allow me to provide 2 different linetypes in add.params = list(linetype=c("solid", "dotted"))
?
I have looked at the source code and using
add.params = list(linetype="dotted")
changes the linetype for both Ex and Rest group. But when trying add.params = list(linetype=c("solid", "dotted"))
I get the error
Error: Aesthetics must be either length 1 or the same as the data (160): linetype
diffusion_data <-
structure(list(FA_full_cov = c(0.153232, 0.164497, 0.111886,
0.14139, 0.130546, 0.18607, 0.181865, 0.139148, 0.178903, 0.136147,
0.140427, 0.143346, 0.140975, 0.148248, 0.128336, 0.147552, 0.126607,
0.127531, 0.153574, 0.124305, 0.168183, 0.146543, 0.135313, 0.139777,
0.148862, 0.154091, 0.131398, 0.145124, 0.136015, 0.128609, 0.159028,
0.158221, 0.124092, 0.139492, 0.142623, 0.195182, 0.229651, 0.144567,
0.169234, 0.181687, 0.136057, 0.14369, 0.143988, 0.152487, 0.109607,
0.139264, 0.139382, 0.13402, 0.159948, 0.141635, 0.177908, 0.133823,
0.196866, 0.204928, 0.15321, 0.150005, 0.126811, 0.158618, 0.135901,
0.147437), age = c(63, 57, 75, 75, 72, 58, 60, 63, 56, 58, 65,
81, 65, 65, 77, 74, 74, 67, 55, 56, 79, 59, 64, 71, 60, 63, 70,
68, 74, 68, 63, 57, 75, 75, 72, 58, 60, 63, 56, 58, 65, 81, 65,
65, 77, 74, 74, 67, 55, 56, 79, 59, 64, 71, 60, 63, 70, 68, 74,
68), Conditions = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L), .Label = c("Ex", "Rest"), class = "factor")), row.names =
c(NA, 60L), class = "data.frame")
library(ggpubr)
a = ggscatter(diffusion_data, y="FA_full_cov", x="age", color = "Conditions", palette = c("black", "grey39"), shape = "Conditions", add = "reg.line", add.params = list(linetype=c("solid", "dotted")), conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson", cor.coef.size = 5, cor.coef.coord = c(70,.25)) +
ggtitle("Hippocampal FA with Respect to Age") + xlab("Age (years)") + ylab("FA") + theme(plot.title = element_text(hjust = 0.5, size = 30)) +
theme(axis.text.x = element_text(size = 20)) +
theme(axis.text.y = element_text(size = 15)) +
theme(axis.title.y = element_text(size = 20)) +
theme(axis.title.x = element_text(size = 20)) +
theme(legend.text = element_text(size=15)) +
scale_shape_manual(values = c(16,1))
ggpar(a, ylim = c(.05,.25))
a
FA_full_cov and age are continuous variables and Conditions has 2 factors (Ex and Rest)
Image of graph when just using add.params = list(linetype="dotted"):