Any idea how to add labels directly to to my plot (geom_text) ?
Here is my sample dataframe, I am plotting three curves ( confirmed, deaths, recovered) but how to add there also colname labels ? I read dataframe from csv file.
print (data)
date confirmed deaths recovered
1 2020-12-01 63883985 1481306 41034934
2 2020-12-02 64530517 1493742 41496318
3 2020-12-03 65221040 1506260 41932091
4 2020-12-04 65899441 1518670 42352021
5 2020-12-05 66540034 1528868 42789879
6 2020-12-06 67073728 1536056 43103827
Here is my code:
data <- structure(list(date = structure(1:6, .Label = c("2020-12-01",
"2020-12-02", "2020-12-03", "2020-12-04", "2020-12-05", "2020-12-06"
), class = "factor"), confirmed = c(63883985L, 64530517L, 65221040L,
65899441L, 66540034L, 67073728L), deaths = c(1481306L, 1493742L,
1506260L, 1518670L, 1528868L, 1536056L), recovered = c(41034934L,
41496318L, 41932091L, 42352021L, 42789879L, 43103827L)), row.names = c(NA,
6L), class = "data.frame")
ggplot(data, aes(x = date, y = confirmed, group=1 ) ) +
geom_line(colour = "blue", size =1, aes(date, confirmed)) +
scale_y_continuous(labels = unit_format(unit = "M", scale = 1e-6)) +
geom_line(color = "red", size = 1, aes(date, deaths)) +
geom_line(color = "#1EACB0", size = 1, aes(date, recovered))
Here is my current plot without labels,
I tried also ggplot with this code label=colnames(stats_data)
, but not working this way,