1

I am trying to align the leader lines from my annotations to their respective points. The points and their connecting lines have been jittered using position = position_jitterdodge(0.05), which the leader lines are not accounting for. Because I used nudge_y to align the labels in rows above and below the points I cannot also use the position = position_jitterdodge (0.05) argument in the geom_text_repel(). Does anyone know how I may go about getting these leader lines to line up with the jittered points, while still keeping the annotations in their current positions? The following is the code I am using and an image of my graph.

ggplot(data = LGR_Data, aes(x = Proj_Year, y = Max_Tidbit_Temp, group = PermID, color = `CTRL/LOGJ`, shape = `CTRL/LOGJ`, fill = `CTRL/LOGJ`)) + 
  geom_line(linetype = "dotted", size = 0.5, position = position_jitterdodge(0.05)) + geom_point(size = 2, position = position_jitterdodge(0.05)) + geom_text_repel(data = subset (LGR_Data, Max_Tidbit_Temp > 23), aes(label = PermID), size = 1, nudge_y = 28 - subset(LGR_Data, Max_Tidbit_Temp > 23)$Max_Tidbit_Temp, direction = "x", angle = 45) + 
  geom_text_repel(data = subset (LGR_Data, Max_Tidbit_Temp < 23), aes(label = PermID), size = 1, nudge_y = 18 - subset(LGR_Data, Max_Tidbit_Temp <= 23)$Max_Tidbit_Temp, direction = "x", angle = 45)

Here's what the current graph looks like

I omitted a lot of formatting on the graph to minimize the length of the above code block.

Data.

LGR_Data <- 
structure(list(PermID = c("PN1301", "PN1303", "PN1304", 
"PN1310", "PN1313", "PN2124", "PN1307", "PN2124", 
"PN2230", "PN2124"), Proj_Year = c(-1, -1, -1, -1, -1, 
-3, -1, -2, -2, -1), CTRL/LOGJ = c("LOGJ", "LOGJ", 
"LOGJ", "LOGJ", "LOGJ", "LOGJ", "LOGJ", "LOGJ", 
"LOGJ", "LOGJ"), Max_Tidbit_Temp = c(23.857, 24.605, 
24.002, 24.098, 24.243, 23.665, 24.026, 22.8, 22.824, 
21.915)), class = c("tbl_df", "tbl", "data.frame"), 
row.names = c(NA, -10L))
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
stkaiser
  • 21
  • 1
  • 1
    Omitting formatting is much appreciated. Could you do more to help us recreate the problem? If you would share just a few rows of data reproducibly, it would give us something to test code on. `dput` is the nicest way to share data because it is copy/pasteable. `dput(LGR_Data[1:10, ])` would be great (or a different subset that the first 10 rows if it is needed to recreate a small portion of the plot and see the issue). – Gregor Thomas Apr 10 '20 at 01:21
  • Here is some data: LGR_Data <- structure(list(PermID = c("PN1301", "PN1303", "PN1304", "PN1310", "PN1313", "PN2124", "PN1307", "PN2124", "PN2230", "PN2124"), Proj_Year = c(-1, -1, -1, -1, -1, -3, -1, -2, -2, -1), `CTRL/LOGJ` = c("LOGJ", "LOGJ", "LOGJ", "LOGJ", "LOGJ", "LOGJ", "LOGJ", "LOGJ", "LOGJ", "LOGJ"), Max_Tidbit_Temp = c(23.857, 24.605, 24.002, 24.098, 24.243, 23.665, 24.026, 22.8, 22.824, 21.915)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -10L)) – stkaiser Apr 10 '20 at 02:00

0 Answers0