The issue is that ggplot2
does not know the column in your dataset it should use for the dodging when it comes to the point geom. For the bar geom, it's obvious because different bars are drawn with different fill colors at the same x axis value. For your point geom, ggplot2
is dodging based on the color
aesthetic. If you want to force grouping or dodging based on a specific column, you should assign that column to the group=
aesthetic.
Here's an example using mtcars
. I'm forcing continuous factors to be discrete via as.factor()
here.
library(ggplot2)
# plot with incorrect dodging
ggplot(mtcars, aes(x=as.factor(carb), y=mpg, fill=as.factor(cyl), color=as.factor(gear))) +
geom_bar(position="dodge", stat="summary", col='black') +
geom_point(position=position_dodge(0.9), size=3) +
theme_classic()

The bars are dodging based on as.factor(cyl)
, assigned to the fill aesthetic, but the points are dodging based on as.factor(gear)
, assigned to the color aesthetic. We override the color aesthetic in the geom_bar()
command (as OP did) by defining col='black'
.
The solution is to force the points to be grouped (and therefore dodged) based on the same column used for the fill aesthetic, so mapping is group=as.factor(cyl)
.
ggplot(mtcars, aes(x=as.factor(carb), y=mpg, fill=as.factor(cyl), color=as.factor(gear))) +
geom_bar(position="dodge", stat="summary", col='black') +
geom_point(aes(group=as.factor(cyl)), position=position_dodge(0.9), size=3) +
theme_classic()

Applied to OP's case, the dodging should work with this code:
ggplot(Data_Task1, aes(Type, Percentage_Correct_WND, fill = Condition, col = Animal)) +
geom_bar(stat = "summary", col = "black", position = "dodge") +
# adjust group here to Condition (same as fill)
geom_point(aes(group = Condition)), position = position_dodge(0.9)) +
labs(x = "", y = "% Correct Without No Digs") +
scale_fill_brewer(palette = "Blues") +
scale_colour_manual(values = c("#000000", "#FF9933", "#00FF33", "#FF0000", "#FFFF00", "#FF00FF")) +
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.line.x = element_line(colour = "black", size = 0.5),
axis.line.y = element_line(colour = "black", size = 0.5)
)