Factorize a numeric variable with Greek expression in labels in R

99封情书 提交于 2019-12-04 19:16:51

Does your locale support these characters? Does '\u03b1' print an alpha character? If not, you'll need to change your encoding. E.g.,

Sys.setlocale('LC_CTYPE', 'greek')

Then replace your calls to expression with the unicode strings for alpha, beta, etc.

df$var<-factor(df$var, levels=c(1,2,3),
               labels=c("1"='\u03b1',
                        "2"='\u03b2',
                        "3"='\u03b3'))

The way you're using expression is only valid for plots. Unless you really need to have Greek letters in your factor, I suggest using the words 'alpha', 'beta', etc. until it's time to plot.

df$var=factor(var,labels=c('alpha','beta','gamma'))

This produces a dataframe with the 1,2,3 transformed into alpha, beta, gamma. Hope this is what you were looking for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!