I have a dataframe containing several columns.
Here is an extract from my data frame:
emp_dayNumber emp_dayName emp_workedDays emp_fullPrice emp_halfFare emp_monthly emp_yearly
1 1 mon TRUE 23.7 117.20 117.66 1058.84
2 2 tue TRUE 47.4 129.05 117.66 1058.84
3 3 wed TRUE 71.1 140.90 117.66 1058.84
I plot the variables emp_fullPrice
, emp_halfFare
, emp_monthly
and emp_yearly
using ggplot2.
In order to display labels, I searched the web and found recommendations for the library ggrepel.
It seems to work, but only for the first geom_line on my plot.
I would like to post a picture but I can't add images since I have low reputation. So instead here's a shitty drawing.
|
|
| / 1209
| ___________________________/
| / ____
| / _________/
| /__________ /
| / \_____/_______
| / / \_______
|/_________________/_________________
As you can see, I managed to get the label for the first value (emp_fullPrice
, so 1209) but not for the others.
Here is the code for my plot:
p<- ggplot(emp.data, aes(emp_dayNumber, emp_fullPrice))+
geom_line(colour=1, size=1.3)+
geom_line(aes(y=emp_halfFare),colour=2, size=1.3)+
geom_line(aes(y=emp_monthly),colour=3, size=1.3)+
geom_line(aes(y=emp_yearly),colour=4, size=1.3)+
#Label at the end of the line
geom_text_repel(
data = subset(emp.data, emp_dayNumber == 154),
aes(label = emp_fullPrice),
size = 4,
nudge_x = 5);
print(p)
From what I understand, it works for the value displayed in ggplot()
, but not in the ones I added with geom_lines()
.
Does anyone have a solution? Thank you kindly.