Hello,
I was wondering how do I make the lines in my line graph to match the same colour as the annotations I have manually entered in the graph. I have attached my current graph along with the desired graph. Any help would be appreciated
Current Graph:
Desired Graph:
data1 <- data_frame(
Animal = c("Bird", "Elephant", "Lion", "Duck", "Crocodile"),
year2013 = c(295,353,201,74,423),
year2018 = c(218,471,205,61,475)
)
### New code starts here
library(tidyr)
data2 <- data1 %>%
pivot_longer(cols = 2:3) %>%
mutate(
year = gsub('year', '', name) %>%
as.numeric
) %>%
select(-name)
animalsinthezoo <- data2 %>%
ggplot(aes(x = year, y = value, group = Animal)) +
geom_line(aes(color = Animal),lwd=1.5) +
geom_text(aes(label = "",group = ""),
data = data2 %>%
filter(year == 2013),
position = position_dodge( width = 1, )) +
geom_text(aes(label = ""),
data = data2 %>%
filter(year == 2018),
nudge_x = 0.1) +
scale_x_continuous(breaks = c(2013, 2018)) +
labs(title = 'Number of Animals in the Zoo',
x = 'Year',
y = 'Frequency',
caption = "Data from Australia Zoo")+
theme_classic()+
theme(text = element_text(family = "montserrat"),
plot.title = element_markdown(size=16, face = "bold",),
axis.ticks.y = element_blank(),
axis.title.x = element_text(size=14),
plot.caption = element_markdown(size=10),
legend.position ='none')
animalsinthezoo + annotate("text", x = 2012.6, y = 420, label = "Crocodile", family = "montserrat", col="darkred")+
annotate("text", x = 2012.6, y = 350, label = "Elephant", family = "montserrat", col="red")+
annotate("text", x = 2012.6, y = 300, label = "Bird", family = "montserrat", color="#1a1919")+
annotate("text", x = 2012.6, y = 200, label = "Lion", family = "montserrat", color="#1a1919")+
annotate("text", x = 2012.6, y = 80, label = "Duck", family = "montserrat", color="#1a1919")
animalsinthezoo