I have a figure with geom_segments of different size. The legend superposes dashes and dots of different sizes. How to prevent that?
Reproductible example:
dataframe = data.frame(country = c("Burundi", "Kenya"),
rate1 = c(10, 3),
threshold1 = c(180, 72.2),
rate2 = c(25, 20),
threshold2 = c(242, 144),
rate3 = c(30,30))
xstart_limit <- 0
xend_limit <- 10000
linetypes <- c("dotted", "dashed")
my_colors <- c("blue","red")
pit_comparison2 <- ggplot() +
geom_segment(aes(x = xstart_limit, y = rate1, xend = threshold1, yend = rate1, colour = country, linetype = country), size = 0.6, data = dataframe[dataframe$country == "Kenya",]) +
geom_segment(aes(x = threshold1, y = rate1, xend = threshold1, yend = rate2, colour = country, linetype = country), size = 0.6, data = dataframe[dataframe$country == "Kenya",]) +
geom_segment(aes(x = threshold1, y = rate2, xend = threshold2, yend = rate2, colour = country, linetype = country), size = 0.6, data = dataframe[dataframe$country == "Kenya",]) +
geom_segment(aes(x = threshold2, y = rate2, xend = threshold2, yend = rate3, colour = country, linetype = country), size = 0.6, data = dataframe[dataframe$country == "Kenya",]) +
geom_segment(aes(x = threshold2, y = rate3, xend = xend_limit, yend = rate3, colour = country, linetype = country), size = 0.6, data = dataframe[dataframe$country == "Kenya",]) +
geom_segment(aes(x = xstart_limit, y = rate1, xend = threshold1, yend = rate1, colour = country, linetype = country), size = 1, data = dataframe[dataframe$country == "Burundi",]) +
geom_segment(aes(x = threshold1, y = rate1, xend = threshold1, yend = rate2, colour = country, linetype = country), size = 1, data = dataframe[dataframe$country == "Burundi",]) +
geom_segment(aes(x = threshold1, y = rate2, xend = threshold2, yend = rate2, colour = country, linetype = country), size = 1, data = dataframe[dataframe$country == "Burundi",]) +
geom_segment(aes(x = threshold2, y = rate2, xend = threshold2, yend = rate3, colour = country, linetype = country), size = 1, data = dataframe[dataframe$country == "Burundi",]) +
geom_segment(aes(x = threshold2, y = rate3, xend = xend_limit, yend = rate3, colour = country, linetype = country), size = 1, data = dataframe[dataframe$country == "Burundi",]) +
scale_linetype_manual(values = linetypes, breaks=c("Burundi", "Kenya")) +
scale_color_manual(values = my_colors, breaks=c("Burundi", "Kenya"))
pit_comparison2
I tried many different things, but never could fix this problem with the legend.