2
I have a line chart and I would like to put the label of the state corresponding to the line, but the label is coming out on each data available and not only the last one:
Code I’m working on:
library(tidyverse)
dados <- read_delim("~/Downloads/arquivo_geral.csv",
";", escape_double = FALSE, trim_ws = TRUE)
dados <- dados[,-1]
dados %>%
filter(casosAcumulados > 9) %>%
ggplot(aes(x = data, y = log(casosAcumulados), col = estado)) +
geom_line() +
geom_text(aes(label = estado),
vjust = -1) +
theme(legend.box = "none") +
ggtitle("Casos confirmados - Brasil", "(Em log)")
Database: https://covid.saude.gov.br/
Look, just because I didn’t understand the doubt right. You want to put the label on the last spot available on each line?
– Jorge Mendes
Yes, and that point representing the state.
– Alexandre Sanches
Do all points end on the same date? If yes I think to put
geom_text(aes(label = estado, x = ultima_data_da_sua_tabela), 
 vjust = -1)
– Jorge Mendes
If the dates are different you can either vector the dates or change the data of the text geom_text (date = . %>% group_by(status) %>% filter(date== max(date)), aes(label = status), vjust = -1)
– Jorge Mendes
I would only change the quantity log (which means less) by a logarithmic scale
meu_grafico + scale_y_log10()
– Tomás Barcellos