'Choosing the color of only one of the plotted elements
I'm using ggplot to plot a set of values in R and want to colour them according to their sensor name. However, I'd like to change the colour of one of the sensors (not all of them as they are many). Do you have any suggestions?
I'm going to use the following command:
ggplot(molted1, aes( Duration,value,group=test ))+
geom_point(aes(color=sensor))+
facet_grid(~test,scales = "free") +
theme_bw()+
scale_x_continuous(breaks=pretty_breaks(n=3))+
theme(legend.position = "none",axis.title=element_text(size=11))+labs(x="",y="Temperature \n(°C)")
Solution 1:[1]
One option is to map the color to the logical test of sensor == selected and then supply the background and highlight colors to scale_color_manual().
If you want to more than one sensor to get highlighted and show different colors for just those ones, you may want to take a look at the {gghighlight} package which does this nicely.
library(tidyverse)
mtcars %>%
ggplot(aes(disp, mpg)) +
geom_point(aes(color = carb == 4), size = 4) +
scale_color_manual(values = c("grey50", "red")) +
facet_grid(~gear)

Created on 2022-04-08 by the reprex package (v2.0.1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dan Adams |
