I found similar questions online, however I seem to be having problems because I am already using fill to color the rest of the bars in the histogram; So when I try to add a manual command to color that separate bar, it overrides it and produces an error.
Here is my ggplot code. I added a column called X$Test that has a single TRUE value at indel_size = 0 where I want to color the bar... Below is the main code, then after that is what I have tried
Scale for 'fill' is already present. Adding another scale for 'fill', which will
replace the existing scale.
Error: Continuous value supplied to discrete scale
In addition: Warning message:
Removed 74 rows containing missing values (position_stack).
The simplest way to colour a single element in a plot is just to add a new element of a different colour over the existing one. You can try adding something like this:
ggplot(data=X, aes(x=indel_size, y=Fq2, fill = indel_size))+
geom_bar(stat="identity")+
scale_fill_gradient2(low="dodgerblue", mid="royalblue", high = "royalblue4")+
ylab("Indel Frequency")+
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank())+
scale_color_continuous(labels = c(-5, 0, 5))+
scale_x_continuous(name = "Indel Size", limits = c(-50,10),
breaks = seq(from = -50, to = 10, by = 10))+
scale_y_continuous(name = "Indel Frequency", limits = c(0,0.5)) +
# Here is what you need
geom_bar(aes(data = filtered_data), stat="identity")
Just for future browsers, the line of code was something like this. First filtering the main dataframe to contain the single point, then applying your suggestion:
Y <- X[X$indel_size == 0, ]
geom_bar(data = Y, aes(x=indel_size, y=Fq2), stat="identity", fill = "firebrick")