[英] How to remove Unknown White Spaces in a vector?
我有一个航向和
temp <- c("hyndman_ensemble","four_theta","tbats")
当我打印Temp时.在Four_theta和tbats之间有未知的空格(在R控制台中try 此操作)
[1] "hyndman_ensemble" "four_theta" "tbats"
我正在用这个临时工来演绎一个传奇.由于图例有空格,如果列表中有5个项目,则数据将丢失.
图例函数(_F):
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.
即使我使用trimws(),也会得到空格(见下图)
谁能告诉我如何删除那些空格或任何替代方案,我可以在没有任何空格的情况下在绘图外打印图例(图例不一定要在顶部)