I drawed a plot with points and a horizontal line. Below is the example code:
dt <- data.frame(ID = c("Line",
"P1",
"P2",
"P3"),
Year = "2016",
Value = c(1, 0.533, 1.233, 0.233))
dt$Value <- format(dt$Value, digits = 2)
# Unexpected horizontal line
ggplot(NULL) +
geom_point(data = subset(dt, ID != "Line"),
aes(x = Year, y = Value, color = ID, shape = ID)) +
geom_text(data = subset(dt, ID != "Line"),
aes(label = subset(dt, ID != "Line")$Value,
x = Year, y = Value)) +
geom_hline(yintercept = as.numeric(subset(dt, ID == "Line")$Value),
color = "red") +
theme_bw()
However, the Figure below seems strange: the red horizontal line is on the y-axis of 0.23, not 1. Why does this happen? Thanks!
Read more here: Source link