R: plot dates in specific locale

谁说胖子不能爱 提交于 2019-12-13 08:59:23

问题


I build a vector d of POSIXlt dates. I make a plot(d, x) using this vector as axis x. but on the plot dates are printed using my computer's locale. I need them to use different locale. how can i choose the format/locale to be used on plots?


回答1:


You should be able to use on Unix based system:

Sys.setlocale("LC_TIME", "en_US"); 

This works for me:

Sys.setlocale("LC_TIME","ru_RU")

df = data.frame(date=c("2012-02-01", "2012-02-01", "2012-02-02")) 
df$day <- weekdays(as.Date(df$date))
df$value <- c(1,10,5)

plot(df$value, xaxt="n") 
axis(side=1, labels=df$day, at=c(1,2,3))

Sys.setlocale("LC_TIME","en_US")

df = data.frame(date=c("2012-02-01", "2012-02-01", "2012-02-02")) 
df$day <- weekdays(as.Date(df$date))
df$value <- c(1,10,5)

plot(df$value, xaxt="n") 
axis(side=1, labels=df$day, at=c(1,2,3))


来源:https://stackoverflow.com/questions/32553466/r-plot-dates-in-specific-locale

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