Let's say that i have the following data.
Data<-structure(list(Date = structure(c(14821, 14821, 14822, 14822,
14823, 14823, 14824, 14824, 14825, 14825, 14826, 14826, 14827,
14827, 14828, 14828, 14829, 14829, 14830, 14830), class = "Date"),
name = c("TSIN", "TSIP", "TSIN", "TSIP", "TSIN", "TSIP",
"TSIN", "TSIP", "TSIN", "TSIP", "TSIN", "TSIP", "TSIN", "TSIP",
"TSIN", "TSIP", "TSIN", "TSIP", "TSIN", "TSIP"), value = c(50.4037680727913,
51.3364809806877, 50.4340417810677, 51.3504773174762, 50.6603181623312,
51.3329488285268, 50.5416074633734, 51.2091857253563, 50.5690544870539,
51.2348346742767, 51.1758823740724, 51.9726318303194, 51.0492677724948,
51.9345778234068, 50.9432096226738, 51.5709622418077, 51.1861995444741,
51.052286506949, 50.8054997798819, 50.9526010710907)), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
I am using scale_color_manual
and scale_linetype_manual
with my final plot. I wanted to include text in LaTex format in my labels. So I used the Tex
command that transform the labels in LaTex format. But I am having a problem because the use of Tex
command generate duplicates labels.
I would like to have two time series and two labels. The code that I am using is the following:
library(latex2exp)
library(tidyverse)
ggplot(Data, aes(x = Date, y=value, colour = name, linetype = name)) +
geom_line() +
theme_test() +
scale_color_manual(values = c("burlywood", "blue3"),
labels = unname(TeX(c("MSHAR-ReCov$^{+}$",
"MSHAR-ReCov$^{-}$")))
) +
scale_linetype_manual(values = 1:2,
labels = unname(TeX(c("MSHAR-ReCov$^{+}$",
"MSHAR-ReCov$^{-}$")))
) +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "bottom",
legend.title = element_blank())+
labs(x = "", y="")