I have a vector with
temp <- c("hyndman_ensemble","four_theta","tbats")
when i print temp. there is unknown spaces in between four_theta and tbats (try this in your R console)
[1] "hyndman_ensemble" "four_theta" "tbats"
I am using this temp in a legend. Due o which the legend has spaces and if there are 5 items in a list the data is missed.
Legend_function:
add_legend <- function(...) {
opar <- par(fig=c(0, 1, 0, 1), oma=c(0, 0, 0, 0),
mar=c(0, 0, 0, 0), new=TRUE)
on.exit(par(opar))
plot(0, 0, type='n', bty='n', xaxt='n', yaxt='n')
legend(...)
}
cl <- rainbow(3)
#Null plot just to display what is happening with the spaces in legend
plot(NULL, xlim=c(0,30), ylim=c(0,100000))
add_legend("topright", legend=c("test1",temp), lty=1,
col=c("orange", cl),
horiz=TRUE, bty='n', cex=0.8)
This is how the plot is looking.
Even If I use trimws(), I get whitespaces (see image)
Can anyone tell me how to remove those spaces or any alternatives where I can print the legend outside the plot without any spaces(It is not mandatory for the legend to be on top)