I ma trying to insert inside the graph a square where I would like to type "something"

Hi there,

I am trying to add a small square to my graph in December 2019 typing "something" inside.
How can I do this in R?
Please see a screenshot of my image.

Here is my code:

map(2016:2020, ~ make_returns(Data_m2, .x)) %>%
do.call('rbind', .) %>%
ggplot(aes(x = year_month, y = mean/100, colour = tercile)) +
scale_color_manual(name = "tercile", values = c("red", "blue"), labels = c("low CSR portfolio", "high CSR portfolio")) +
scale_linetype_manual(name = "tercile", values = c("dashed", "solid"), labels = c("low CSR portfolio", "high CSR portfolio")) +
labs(x = "time", y = "returns") +
scale_x_date(breaks = as.Date(c("2016-01-31", "2017-01-31", "2018-01-31","2019-01-31", "2020-01-31", "2020-12-31")), date_labels = "%Y (%b)") +
geom_vline(xintercept = as.Date(c("2017-01-31", "2017-01-31", "2018-01-31","2019-01-31", "2020-01-31")), linetype = 3) +
scale_y_continuous(labels = scales::percent, breaks = c(-0.15, -0.10, -0.05, 0, 0.05, 0.10, 0.15)) +
geom_hline(yintercept = 0) +
theme_classic() +
theme(legend.position="bottom") +



Hello, your code is particularly useful as forum users will fail to be able to run it by virtue of not having your private objects. Data_m2 etc. See the reprex guide to overcome this.

In general though , the solution would be to annotate with a geom_text or geom_label depending on the required effect. see for example:
How to annotate a plot in ggplot2 – the R Graph Gallery (r-graph-gallery.com)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.