问题描述
我是 R 的初学者。我花了一天的大部分时间都没有找到解决方案。
我需要一个在 x 轴上带有日期的二维散点图。这是我所拥有的:
################## CSV file looks like this
#;Datum;Summe;dink;
#;1.1.2010;10;2;
#;1.2.2010;20;3;
#;10.3.2010;40;4;
#;1.4.2010;70;3;
#;15.5.2010;80;5;
#;1.6.2010;100;6;
#;24.7.2010;200;5;
#;1.8.2010;150;7;
#;1.9.2010;130;8;
csvu<-read.csv("2D-plot-Tabelle.csv",sep = ";",encoding="UTF-8") # from Numbers
# as.Date converts into class Date
csvu$Datum <- as.Date(csvu$Datum,"%d.%m.%Y") # this is the read format. capital Y = year with century
plot(csvu$Datum,csvu$Summe,main="This is my plot",xlab="Datum",ylab="Summe",type = "b",# both lines and dots
lwd = 2,# line width
# col = "darkgreen",# col = symbol surround color
col = rainbow(25),pch=16,# pch = symbol interior color,see http://applied-r.com/r-graphics-plot-parameters/#axes
cex = 2) # cex = size of plot symbols
plot() 显然应用了默认的 x 轴编号,它给出了 5 个月的月份值,没有日或年。
我需要 x 轴刻度和日期的“编号”,格式为“%d.%m.%Y”,每月间隔和根据日期。我更喜欢垂直书写日期。有什么建议吗?
######## 自己找到了解决办法。也许对其他人很有趣:
# add xaxt="n",as plot-parameter (disable x-axis numbering and ticks),than
axis.Date(1,at=csvu$Datum,labels=format(csvu$Datum,"%d %b %Y"),las=2) # las=2 vertical,1 horiz.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)