Add point, text and line to a geom_line ggplot

#Hi there! I was making a simple geom_line plot, but I am getting stuck adding some features to it. My idea is putting a point on the TOP of the 3 lines, add the number of this point and draw a simple line that connect this point with the xlabel. Hope anyone can help me and I will send tons of thanks!

#CODE

ObservationDate <- c("1/3", "2/3", "3/3","4/3","5/3","6/3","7/3","8/3","9/3","10/3")
Confirmed_per_day <- c(234,345,567,345,547,345,243,234,546,345)
Deaths_per_day <- c(123,143,145,123,226,136,148,160,167,124)
Recovered_per_day <- c(345,347,435,370,456,267,455,556,234,236)
coronavirus_daily_Spain <- data.frame(ObservationDate,Confirmed_per_day,Deaths_per_day,Recovered_per_day)
View(coronavirus_daily_Spain)

#GRAPH

library(ggplot2)

q <- ggplot(data=coronavirus_daily_Spain, aes(x=ObservationDate))+
geom_line(aes(y = Confirmed_per_day, group=1, color = "steelblue"), size=2) +
geom_line(aes(y = Deaths_per_day, group=1, color = "darkred"), size=2) +
geom_line(aes(y = Recovered_per_day, group=1, color = "green"), size=2) +
scale_color_discrete(name = "Data Series", labels = c("Deaths", "Recovered", "Confirmed"))

q + theme(axis.text.x = element_text(angle = 90, hjust = 1))

print(q + ggtitle("Evolution of Covid-19") + theme(plot.title = element_text(hjust = 0.5)))

Hi,

I don't have the time to draw this for you, but a couple of hints that might help:

  1. Your ObervationDate column would be better as dates, rather than character strings or a factor, which it will have defaulted to (unless you have a recent version of R, I believe?). See the lubridate package or as.Date to achieve this. When I run your code the x axis is ordered 1/3 10/3 2/3 3/3 etc, as the character strings get default alphanumeric ordering.
  2. If you put your data.frame in long format it fits the ggplot2 style of plotting better, you can call geom_line just once. See gather or it's replacement pivot_longer in the tidyr package.
  3. If you install the ggrepel package, then geom_text_repel or geom_label_repel should be able to help you with yout data labels and connecting lines. Personally I think it might get a bit crowded and chaotic, in which case you might filter to only display the labels for points you want to highlight/talk about.

I hope this helps a bit.

Ron.

Is it what you are after ?

https://forum.posit.co/t/problem-with-geom-point-ggplot/64336/3

Hi Ron, sorry I didn´t realice about the dates format as I have the last versión of R. I already have the solution, but thank you very much for your time, I really apreciate that.

Rubén.

Yes sorry you solved the problem yesterday, it was the same problem. But if you want to send me the code you did, I will apreciate too.

Thank you very much for your time!

Rubén.

No worries. Glad you got a solution.

Looking at @Andrzej's solution, I realised I had misread your query (scanned thought it a bit too quickly)

Actually this is Andresrcs solution in another post that
I directed you to, so credit goes to Him.
regards,
Andrzej

I did notice you directed @rubensamp to another post for the solution. That post seems to be by @rubensamp too, so now I'm wondering why he's asking the same question twice in quick succession?

This topic is duplicated here: Add point, text and line to a geom_line ggplot