I'm trying to assign labels to points in ggplot based on a certain criteria (value > 0.4), but I want the colour of the points to apply based on the team name. I can do colour and labels for ALL data points (which looks really messy), but struggling to apply the label criteria.
Have tried copying this example, but it doesn't allow for colouring the points by team:
Plot <- ggplot(data = df, aes(x=Prem$Expected.Goals.p90..exl.pens., y=Prem$Expected.Assists.p90, color=Prem$Team, label=Prem$Player)) +
geom_point() +
geom_abline(intercept = 0, linetype = 2, colour = "darkblue") +
scale_x_continuous(name = "Non-penalty Expected Goals per 90", limits = c(0, 0.7)) +
scale_y_continuous(name = "Expected Assists per 90", limits = c(0, 0.7)) +
theme_bw() +
scale_colour_manual(values = c("firebrick1", "green", "navy", "darksalmon", "brown4", "darkgreen", "dodgerblue", "yellow", "orange", "blue", "black", "lightblue"))
Plot + geom_label_repel(aes(label = (Prem$Player)),
box.padding = 0.35,
point.padding = 0.5,
segment.color = 'grey50')
df1 <- subset(df, Prem$Expected.Goals.p90..exl.pens. > 0.4)
Plot + geom_label_repel(data = df1, aes(x=df1$Expected.Goals.p90..exl.pens., y=df1$Expected.Assists.p90, label=df1$Player),
size = 5,
box.padding = unit(0.35, "lines"),
point.padding = unit(0.3, "lines")
)
Have tried to create a subset df1 to deal with this, but I'm getting the following error message:
Error: Aesthetics must be either length 1 or the same as the data (8): x, y, label, colour