1 year ago
#175369
user13069688
Change key glyphs in ggplot2
I am having two issues with my ggplot. I am trying to plot two continuous variables in a scatterplot, stratified by a categorical variable (4 levels).
The first one is that the plot produces the letter "a" in the legend instead of a line. I know that there is something off with the glyph but I cannot figure it out.
The second issue is that when I use label.y = 10 in the stat_cor() function from the ggpubr package the correlations of the 4 groups collapse all together. label.x works fine.
My code is the following:
library(ggplot2)
library(ggpubr)
df <- data.frame(categories = as.factor(c(1,2,3,3,4,1,4,2,2,1,2,3,4)),
var1 = c(1,11,13,2,5,5,4,10,7,1,2,4,5),
var2 = c(2,10,12,15,14,1,3,7,11,5,6,7,5))
b <- ggplot(df, aes(x = var1, y = var2, colour = categories)) +
geom_point()+
geom_smooth(method = "lm", se = FALSE, fullrange = TRUE) +
scale_color_manual(values = c("#feedde", "#fdbe85", "#fd8d3c", "#d94701")) +
theme_bw() +
ggpubr::stat_cor(aes(color = categories), label.x = 3, label.y = 10) +
ggtitle("Title") +
theme(plot.title = element_text(hjust = 0.5)) +
xlab("Var1") + ylab("Var2") +
labs(color = "Categories")
b
r
ggplot2
glyph
0 Answers
Your Answer