I have the following data which I have graphed in a double line graph. I want to add an asterisk whenever significance is "y."
structure(list(Year = c(0, 1, 2, 3, 0, 1, 2, 3), school_type = c("Management Change",
"Management Change", "Management Change", "Management Change",
"Full Closure", "Full Closure", "Full Closure", "Full Closure"
), pct_change = c(3.7, 2, 0.8, -1.1, 9.2, 6.9, 5.4, 6.6), significance = c("y",
"n", "n", "n", "y", "y", "y", "y")), row.names = c(NA, -8L), class = c("tbl_df",
"tbl", "data.frame"))
I used the following code to create asterisks (after consulting R ggplot2: add significance level to line plot), but the problem is that I can't move those asterisks up to get them out of the point of the points, or change the font to be what I want. I tried nudge_y but it didn't work.
ggplot(fig4, aes(x=Year, y=pct_change, color=school_type, group=school_type)) +
geom_line(size=1) +
geom_point(size=3) +
theme_bw(base_family = "Georgia") +
geom_point(data = fig4[fig4$significance == "y", ], shape = "*", size=4.233, color="black")
Whenever I want to add significance asterisks to a bar graph, it's easy. I put in:
ggplot(df, aes(label = ifelse(significance == "y", "*",""))
However, this doesn't work at all for line graphs for some reason. Why not?