1

I have my database table from which i retrieve a column and plot it using plot function.

Here is column of table

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

Here 60 rows are present but i am showing only 10 rows. when i try to plot the graph i am getting a straight line parallel to x axis but here profit is changing, so i don't think that it should parallel to x-axis.Since table is present in database in aws i am retrieving the profit column from table first then plotting using plot function.Here is plot function

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

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

i am also getting warning messages here:

 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

But when i remove type = "l", warning message disappears. But I want the plot in straight line format only.

zx8754
  • 52,746
  • 12
  • 114
  • 209
user11034850
  • 35
  • 1
  • 9
  • 1
    Is "Choices" not supposed to be "choices"? Also, add output of sessionInfo(). This works for me without warnings: `plot(1:10, type = "l")`. Make your data reproducible, most likely your Profit column is not numeric, see [this thread](http://r.789695.n4.nabble.com/R-help-with-plot-td810106.html). – zx8754 May 09 '19 at 20:05

1 Answers1

0

Based on this R Help thread, the Profit column is class of factor, let's test:

Below works fine, when numeric:

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

When we have factors, plots but with warnings:

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
zx8754
  • 52,746
  • 12
  • 114
  • 209
  • Thanks for your reply.Here choices is of type list, which will include all the tuples in Profit.Profit can consists of any number of tuples so i cannot use **plot(1:10, type = "l")** here.I tried to convert choices datatype into numeric by **as.numeric(as.character(choices))** but getting datatype as double not numeric. – user11034850 May 10 '19 at 04:02
  • @user11034850 Please provide [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example): `dput(head(choices))` – zx8754 May 10 '19 at 06:02
  • 1
    Thanks for giving direction **as.numeric(as.character(unlist(choices)))** solves my problem @zx8754 – user11034850 May 10 '19 at 16:23