Entering edit mode
10 months ago
rene.j.erhardt
▴
30
I made a scatterplot showing correlations between 2 groups. Several participants have the same datapoints, so I got fewer dots than participants. Is there a way to put a number in the plot next to every dot indicating how many they represent?
Here is my code and plot:
ggscatter(df, x = "Change", y = "T0",
color="Group",palette = c("red", "blue"),
add = "reg.line", conf.int = TRUE,
add.params = list(color = "brown"),
cor.coef = TRUE, cor.method = "spearman",
cor.coef.coord = c(2,5),
cor.coef.size = 5,
ylim = c(0, 5),
xlab = "x", ylab = "y") +
scale_x_continuous(n.breaks=7) +
theme(legend.position = "right", legend.justification = "top", legend.title = element_blank())+
theme(axis.line=element_line(size=1))+
theme(text = element_text(size = 13))
It appears to be quit tricky. When I add the lines: geom_count() + scale_size_area(breaks = c(1,2,3,4,5)) to the end, I get which would be ok, but I loose the colours. Maybe someone hs an idea how to get them back?
The reason it looks like this is because you're plotting the circles with the desired size on top of your colored dots. You can even see this at (4,3) and (2,1). See if you can add a color aesthetic within
scale_size_area
, or better yet, modify your input dataframe so that it includes the number of participants represented by each dot.