0

For whatever reason, the last point in the platelet data goes down instead of up when I plot it. Any ideas? I've redone EVERYTHING and it won't change.

Here's my code:

dates2 <- as.Date(c("2019-02-04", "2019-02-06", "2019-02-08", "2019-02-11", "2019-02-12", "2019-02-13", "2019-02-14", "2019-02-15", "2019-02-19", "2019-02-25", "2019-03-05", "2019-03-20", "2019-05-01", "2019-07-24", "2019-11-13", "2021-06-29", "2021-09-15", "2021-10-20", "2022-02-01", "2022-05-10", "2023-03-23", "2023-06-15", "2023-09-28", "2024-02-08", "2024-04-15", "2021-04-12", "2021-09-16", "2022-02-18", "2022-09-13", "2023-03-14", "2023-09-12", "2024-03-12", "2024-09-17", "2024-10-15", "2025-11-03", "2025-04-16", "2025-10-22"))
wbc2 <- c(3.7, 2.8, 2.3, 0.3, 0.3, 0.3, 0.5, 0.7, 1.1, 2.9, 4.0, 8.2, 7.3, 6.8, 7.4, 7.2, 8.4, 7.4, 7.7, 7.0, 8.3, 6.5, 8.4, 7.2, 6.8, 8.9, 7.6, 7.8, 8.7, 7.6, 8.3, 7.5, 6.91, 7.3, 7.6, 6.7, 7.2)
plt2 <- c(73, 72, 75, 86, 74, 71, 73, 79, 132, 165, 126, 132, 138, 152, 153, 153, 171, 151, 161, 158, 150, 147, 142, 136, 146, 165, 166, 162, 156, 170, 143, 141, 133, 162, 134, 141, 145)
# anc <- c(1.3, 1.4, 1.7, 0.1, 0.1, 0.0, 0.1, 0.2, 0.3, 1.1,2.24, 6.6, 5.4)

plt2_df <- data.frame(dates2, plt2)
wbc2_df <- data.frame(dates2, wbc2)
# anc_df <- data.frame(dates2, anc)

pplot2 <- ggplot(plt2_df, aes(dates2, plt2)) +
  geom_point() +
  geom_line() +
  labs(
    title = "Platelets since cladribine",
    subtitle = "dashed line = lower range of normal",
    caption = "Source: MyChart data, Yale"
  ) +
  geom_hline(yintercept = 150, lty = 2, col = "red") +
  xlab("date") +
  ylab("platelet count") +
  theme_bw()
pplot2
New contributor
bh7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • 7
    Welcome to SO! I'm not sure if I understand the issue correctly. The data points are connected in date order. If you want to connect the points in the order they appear in your data, then perhaps you want geom_path instead of geom_line. Commented Nov 18 at 16:22
  • 5
    Can you clarify exactly what you were expecting? The last three dates in your data were "2025-11-03", "2025-04-16", "2025-10-22". Which are out of order according to the calendar. When R draws a line plot, it draw the points in the correct x-axis order since that's how most line plots work. Commented Nov 18 at 16:28
  • 4
    The last two data points are (2025-10-22, 145) and (2025-11-03, 134). 134 is smaller than 145, so isn't it correct for the last point to go down? Commented Nov 18 at 16:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.