【问题标题】:Plot window appears but no plot - R debian stretch出现绘图窗口但没有绘图 - R debian stretch
【发布时间】:2017-09-17 00:18:25
【问题描述】:

我正在从 R 终端运行以下 R 脚本,

library(xts)
library(csv)
library(graphics)

dt <- data.frame(read.csv("/home/russellb/tmp.csv", header=TRUE, sep=','));
df <- xts(dt[-c[1], as.Date(dt$Datum));

print(head(df[,2]));
plot(df[,2])

我在 R 控制台中得到以下内容,

           Amount$ 
2016-03-03  630200
2016-03-04 2971100
2016-03-05 3023800
2016-03-06 1669300
2016-03-07 1704900
2016-03-08 1415500

没有错误或警告消息。

出现绘图窗口,但未绘制数据,绘图窗口为空,标题为“R Graphics: Device 2 (ACTIVE)”。

当我输入时,

x11()

在 R 控制台中,会出现一个绘图窗口,当我输入以下内容时,

plot(1:100)

我得到了绘制在窗口中的数据。

我尝试在脚本中添加x11(),但没有任何运气。我在我的 Debian-stretch 9.1

上运行 R-3.3.3

我的sessionInfo()输出如下,

R version 3.3.3 (2017-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lattice_0.20-34 csv_0.5         xts_0.10-0      zoo_1.8-0      

loaded via a namespace (and not attached):
[1] grid_3.3.3

dput(head(dat))的输出

structure(list(Datum = structure(c(505L, 504L, 503L, 
502L, 501L, 500L), .Label = c("2016-03-03", "2016-03-04", "2016-03-05", 
"2016-03-06", "2016-03-07", "2016-03-08", "2016-03-09", "2016-03-10", 
"2016-03-11", "2016-03-12", "2016-03-13", "2016-03-14", "2016-03-15", 
"2016-03-16", "2016-03-17", "2016-03-18", "2016-03-19", "2016-03-20", 
...
"2017-07-17", "2017-07-18", "2017-07-19", "2017-07-20", "2017-07-21", 
"2017-07-22", "2017-07-23"), class = "factor"), Amount = c(1700500L, 
2286600L, 3018700L, 2012100L, 2357600L, 1983500L), DM50 = c(230L, 
294L, 454L, 267L, 316L, 270L), DM10 = c(226L, 399L, 364L, 330L, 
371L, 298L), DM5 = c(516L, 699L, 636L, 573L, 676L, 549L), DM1 = c(665L, 681L, 667L, 606L, 686L, 610L)), .Names = c("Datum", Amount", "X50", "X10", "X5", "X1"), row.names = c(NA, 6L), class = "data.frame")

任何帮助将不胜感激。

【问题讨论】:

  • 您应该发布dput(head(dt)) 的输出。目前尚不清楚您的数据框中包含什么。在列名中看到“$”很奇怪。
  • 我的print(head(df[,2])) 输出显示数据已正确加载。但没有绘制。谢谢@42-
  • 添加信息@42-
  • 我认为你缩写了输出。不可能将该结构分配给变量名。我能看到的看起来有点奇怪。 .Names = c("Datum", Amount", "X50", "X10", "X5", "X1") 属性的字符值与结构的“内部”不同:Datum,Amount, DM5000, DM1000, DM500, DM100
  • 是的。我在发布之前做过,忘记更改相应的内联条目。现在它们是一致的。

标签: r linux plot debian


【解决方案1】:

我怀疑问题的出现是因为第一列似乎是 Date 并不是真正的 R-Date。这是一个因素。您可以通过执行将其转换为“真实”日期:

df$Datum <- as.Date( as.character( df$Datum ) )

R 的绘图函数处理因素与日期完全不同。

【讨论】:

    猜你喜欢
    • 2015-12-17
    • 2012-08-15
    • 2011-01-09
    • 2012-10-20
    • 2014-06-20
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多