I'm trying to create a rather simple bar graph, and add the values on top of each bar for clarity (rather than using a scaled axis).
This is my code:
pbias <- ggplot(PSS.diff.means, aes(x=Control, y=PSS, ymax=37, fill=Modality)) +
theme_bw() +
theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.line = element_blank(), axis.text.y=element_blank(), axis.text.x=element_blank(), axis.ticks=element_blank(), axis.title = element_blank(),
legend.justification = 'left') +
geom_bar(position = "dodge", stat='identity') +
scale_fill_manual(values=c("lightblue","orange")) +
coord_cartesian() +
ggtitle("Normalized PSS values indicate threat bias per condition")
pbias + geom_text(aes(label=round(PSS,2), colour=Modality), hjust=-.2) + coord_flip()
and this is what I'm getting:
https://i.stack.imgur.com/MxiIQ.png
I'm trying to fix two things by tweaking all sorts of stuff in the geom_text() function, but I'm getting nowhere. First, I can't seem to get the values to be on the correct positions, as I want them to be in the middle of their respective bars, not on the position of the grouping variable. Second, somehow my colour scheme gets flipped in the geom_text, even though it seems to me like I'm using the same variable I used to define my colour fill. Any ideas?
Here's the dataframe I used:
structure(list(Modality = structure(c(1L, 2L, 1L, 2L), contrasts = structure(c(-1,1), .Dim = c(2L, 1L), .Dimnames = list(c("0", "1"), NULL)), .Label = c("Visual","Tactile"), class = "factor"), Control = structure(c(1L, 1L,2L, 2L), contrasts = structure(c(-1, 1), .Dim = c(2L, 1L), .Dimnames = list(c("0", "1"), NULL)), .Label = c("Comparison", "Pain control"), class = "factor"), PSS = c(8.22627487231047, 1.37218085266906,5.93659638506416, 33.4255762835254)), .Names = c("Modality","Control", "PSS"), row.names = c(NA, -4L), class = "data.frame")