Update: It looks like this issue might be due to a bug. From my pretty basic understanding of the github issues threads, it looks like they are aware of it and looking to fix it in the next update.
The geom_text function is placing incorrect labels when I use a variable for facet_wrap that I have re-ordered into levels. This graph is supposed to be labeled with values from the x-axis. But obviously the labels are wrong and when I compared them to my data (see below) it was obvious that the faceting was not ordering the geom_text into the levels I wanted. So the values for the "1 to 5 years" group are used to label the "Under a year" facet.
data frame is TenQ1 (short for Tenure, Question 1)
Groups: Question, Tenure [5]
Question Tenure Value Value_Mean n
<chr> <fct> <chr> <dbl> <int>
1 Q1 1 to 5 years Communications 2.47 34
2 Q1 1 to 5 years Community 2.41 22
3 Q1 1 to 5 years ContImp 2.68 37
4 Q1 1 to 5 years Customers 1.74 50
5 Q1 1 to 5 years Employees 2.02 45
6 Q1 1 to 5 years Integrity 2.09 57
7 Q1 1 to 5 years Preparedness 2.5 24
8 Q1 1 to 5 years Teamwork 2.40 43
9 Q1 10 to 20 years Communications 2.76 34
10 Q1 10 to 20 years Community 2.67 18
# ... with 30 more rows
Here is the code I am using for my plot:
ggplot(TenQ1, aes(x = Value, fill = n))
+geom_point(aes( y = Value_Mean,fill = n), size = 5,shape = 21)
+facet_wrap(~Tenure, ncol = 3)
+scale_fill_gradientn(colors = rainbow(5))+scale_y_reverse(limits = c(4,1))
+theme(axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)), axis.text.x=element_text(size = rel(1.3), angle=45, hjust=1))
+geom_text(aes(y = Value_Mean), nudge_y = .3, size = 3, label = round(TenQ1$Value_Mean, digits=1))
+ labs(fill = "Number of staff \n that ranked this \n value in top 4",y = "Average rank from 1 to 4 for each value")
I thought about removing the TenQ1$ from my label in geom_text but then I get the error "object 'Value_Mean' not found".