【问题标题】:Getting warning message while using plot function使用绘图功能时收到警告消息
【发布时间】:2019-09-27 17:14:51
【问题描述】:

我有我的数据库表,我从中检索一列并使用绘图函数绘制它。

这是表格的列

 Profit
 1   21200                    
 2   28000
 3   29600
 4   30200
 5   33000
 6   26800
 7   32600
 8   30000
 9   28000
10  34000

这里有 60 行,但我只显示 10 行。 当我尝试绘制图表时,我得到一条平行于 x 轴的直线,但这里的利润正在变化,所以我认为它不应该平行于 x 轴。由于表存在于 aws 的数据库中,我正在检索首先从表中提取利润列,然后使用绘图函数进行绘图。这里是绘图函数

 choices = dbGetQuery(pool,"select Profit from input11;")

plot(Choices, type = "l", lwd = 3, main = "Profit",col = "green", xlab = 
"Number of Overbooking", ylab = "Profit")

我也在这里收到警告消息:

 Warning messages:
1: In plot.window(xlim, ylim, log, ...) :
  graphical parameter "type" is obsolete
2: In axis(side = side, at = at, labels = labels, ...) :
 graphical parameter "type" is obsolete
3: In title(xlab = xlab, ylab = ylab, ...) :
  graphical parameter "type" is obsolete

但是当我删除type = "l" 时,警告信息消失了。但我只想要直线格式的绘图。

【问题讨论】:

  • “选择”不应该是“选择”吗?另外,添加 sessionInfo() 的输出。这对我有用,没有警告:plot(1:10, type = "l")。使您的数据可重现,很可能您的利润列不是数字,请参阅this thread

标签: r warnings line-plot


【解决方案1】:

基于这个R Help threadProfit列是因子类,我们来测试一下:

下面的工作正常,当数字时:

plot(1:10, type = "l")

当我们有因子、情节但带有警告时:

plot(factor(1:10), type = "l")

Warning messages:
1: In plot.window(xlim, ylim, log = log, ...) :
  graphical parameter "type" is obsolete
2: In axis(if (horiz) 2 else 1, at = at.l, labels = names.arg, lty = axis.lty,  :
  graphical parameter "type" is obsolete
3: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) :
  graphical parameter "type" is obsolete
4: In axis(if (horiz) 1 else 2, cex.axis = cex.axis, ...) :
  graphical parameter "type" is obsolete

【讨论】:

  • 感谢您的回复。这里的选择是列表类型,它将包括 Profit 中的所有元组。Profit 可以包含任意数量的元组,所以我不能使用 plot(1:10, type = "l") 在这里。我尝试通过 as.numeric(as.character(choices)) 将选择数据类型转换为数字,但将数据类型作为双精度而不是数字。
  • @user11034850 请提供reproducible example:dput(head(choices))
  • 感谢您的指导as.numeric(as.character(unlist(choices))) 解决了我的问题@zx8754
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多