0

I have made it so that on the scatter plot certain points have a label, but I can not figure out to give the corresponding points a color so it stands out from the rest of the points

xValueL <- "Penetration"
yValueL <- "PromotionVolume"


target <- c("RIS","JUICE" ,"ÖLKORV","MAJONNÄS", "SKALDJUR", "BACON")
#Plot
ggplot(mydata, aes_string(x=xValueL, y= yValueL)) +
  geom_point() +
  geom_label(
    data=mydata %>%filter( Category %in% target),
    aes(label=Category, hjust = -0.1,  vjust = 0)
  )

enter image description here

Quinten
  • 35,235
  • 5
  • 20
  • 53
  • You could use the package [`gghighlight`](https://yutannihilation.github.io/gghighlight/index.html) for this. I could create an example as an answer, but you would have to provide a reprex. – jpiversen May 29 '22 at 10:04
  • Maybe [r - ggplot2 - highlighting selected points and strange behavior](https://stackoverflow.com/questions/11467965/r-ggplot2-highlighting-selected-points-and-strange-behavior) or [Highlight a specific point in ggplot2](https://stackoverflow.com/questions/67812739/highlight-a-specific-point-in-ggplot2) help to answer your question. – stefan May 29 '22 at 10:12
  • Please share your data using `dput`? – Quinten May 29 '22 at 10:27
  • I have used @stefan solution and it works ```ggplot(mydata, aes_string(x=xValueL, y= yValueL)) + geom_point() + geom_label( data=mydata %>%filter( Category %in% target), # Filter data first aes(label=Category, hjust = -0.1, vjust = 0) )+ geom_point(data=mydata %>%filter( Category %in% target), aes_string(x=xValueL, y= yValueL), color="red") ´´´ – Sten B. Rasmussen May 29 '22 at 15:33

0 Answers0