Reputation: 8454
I have the dataframe below:
df <- data.frame(result=floor(rnorm(1000, 100, 20)))
to create this histogram:
require(scales)
df <- data.frame(result=floor(rnorm(1000, 100, 20)))
ggplot(df)+
geom_histogram(aes(result, fill = (result<=80 | result > 95)),
binwidth = 5, center = 2.5, color = "black") +
scale_fill_manual(values=c("darkblue", "lightblue"), guide = F) +
labs(y = "Frequency", x = "Result") + scale_y_continuous(labels = comma)+
theme_classic(base_size = 16)+annotate("label",x=130,y=90, label = "text" )
I have added a label but I would like to know if there are other shapes -maybe colored- in which I could put the text. Ideally an arrow but also the label with the text and the arrow below.
Upvotes: 5
Views: 8277
Reputation: 66935
Adding a narrow arrow can be done like so:
... +
annotate("segment", x = 87.5, y = 110, xend = 87.5, yend = 98,
arrow = arrow(type = "closed", length = unit(0.02, "npc")))
Or a thicker version with text in it:
...+
annotate("segment", x = 87.5, y = 115, xend = 87.5, yend = 100,
size = 8, linejoin = "mitre",
arrow = arrow(type = "closed", length = unit(0.01, "npc"))) +
annotate("text", x=87.5,y=115, label = "text", color = "white",
angle = 90, hjust = 1.5, size = 5, fontface = "bold")
Upvotes: 13