I am trying to replicate this line chart from highcharts. The annotations are wrapped in speech/text bubbles. I have tried to do this in ggplot with geom_label. To get the points, I've added geom_point with a filled triangle shape up or down. Whilst this works for the dark and opaque fills and colours, it does not work for white semi transparent fill with black colour outline, as you can clearly see the triangle's base.
Does anybody know a way around this or a better approach?
Code:
library(ggplot)
ggplot(france, aes(Distance, Elevation))+
geom_area(fill = "#90ed7d", color = "#434348",
size = 0.7, alpha = 0.5)+ # area chart
# location labels
geom_label(aes(x, y-200, label = text), data = plot_labels[-3,],
label.padding = unit(.4, "lines"), label.size = unit(.4, "mm"),
label.r = unit(.05, "lines"), alpha = 0.5,
vjust = 0.5, size = 3, family = "Lucida Grande")+
# location labels points
geom_point(aes(x, y-105, fill = "white"), data = plot_labels[-3,],
shape = 24, fill = "#FFFFFF80", size = 3, color = "black")+
# elevation labels
geom_label(aes(x, y+200, label = text), data = text_labels[-3,],
label.padding = unit(.4, "lines"), label.size = unit(.4, "mm"),
label.r = unit(.05, "lines"), color = "#404040",
fill = "#404040",
vjust = 0.5, size = 3, family = "Lucida Grande")+
# text in white color for elevation labels
geom_text(aes(x, y+200, label = text), data = text_labels,
vjust = 0.5, size = 3, family = "Lucida Grande",
colour = "#ffffff")+
# elevation labels points
geom_point(aes(x, y+105), data = text_labels[-3,],
shape = 25, fill = "#404040", size = 3, color = "#404040")+
scale_y_continuous(labels = function (x) paste(x, "m"),
limits = c(0, 1600),
expand = c(0,0),
breaks = seq(0, 1500, 500))+
scale_x_continuous(labels = function(x) paste(x, "km"),
expand = c(0,1.5), breaks = seq(0, 200, 25),
limits = c(0, max(france$Distance)))+
ggtitle("2017 Tour de France Stage 8: Dole - Station des Rousses")+
theme_minimal()+
theme(panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
axis.ticks.x = element_line("#d6d7e6"),
axis.ticks.length.x = unit(.25, "cm"),
text = element_text("Lucida Grande", size = 11))
Data:
france <- read.csv(file = "https://raw.githubusercontent.com/mrRlover/data/main/Stackoverflow/tour_de_france_stage_8.csv")
plot_labels <- read.csv("https://raw.githubusercontent.com/mrRlover/data/main/Stackoverflow/labels.csv")
text_labels <- read.csv("https://raw.githubusercontent.com/mrRlover/data/main/Stackoverflow/text_labels.csv", encoding = "UTF-8", sep = ",")
colnames(france) <- c("Distance", "Elevation")
colnames(plot_labels) <- gsub("point__", "", colnames(plot_labels))
colnames(text_labels) <- gsub("point__", "", colnames(text_labels))
text_labels$text <- gsub("<br>", "\n", text_labels$text)
Current output: