Rollo99
Rollo99

Reputation: 1613

Why "plot" doesn't display the line?

I have this plot that it's creating me some problems as I don't manage to plot the red line between CIs. This plot is the fifth of a series of plots that are identical in nature and code. Only in this case, the line doesn't show up. I can't figure it out why.

This is my dataset and code:

ap_pp = structure(list(appp = c(0.0534256470459521, 0.318338283911788, 
0.510498594892796, 0.659918013907143, 0.847855923395071, 1.33512933449448, 
1.79114871626335), LB_T = c(-0.0039953960988687, -0.00128119112255898, 
1.231602663197e-05, 0.000409544070864543, 0.00117091129359269, 
0.00719127778296817, 0.0141800410470155), UB_T = c(0.00506390903978775, 
0.00764795680079474, 0.010197655871224, 0.0127888162072783, 0.0157862071743087, 
0.0195113089069214, 0.0216429332782514), LB_T = c(-0.0039953960988687, 
-0.00128119112255898, 1.231602663197e-05, 0.000409544070864543, 
0.00117091129359269, 0.00719127778296817, 0.0141800410470155), 
    UB_T = c(0.00506390903978775, 0.00764795680079474, 0.010197655871224, 
    0.0127888162072783, 0.0157862071743087, 0.0195113089069214, 
    0.0216429332782514)), class = "data.frame", row.names = c(NA, 
-7L)) 
  plot(ap_pp$appp, ylim = range(c(ap_pp$LB_T, appp$UB_T)), xlab = "", ylab = "", main = "LSAP", type = "n", xaxt = "n")

axis(1, at = 1:7, labels = load_unscaled_m$Date)

with(ap_pp, polygon(c(xx,rev(xx)),c(LB_T,rev(UB_T)), col = "#FFA6AA", border = FALSE))
 abline(h = 0, col = "black", lty = 2)
  lines(ap_pp$appp, type = "o", lwd = 2, col = "red")

Can anyone help me?

Thanks

Upvotes: 0

Views: 421

Answers (1)

Gregor Thomas
Gregor Thomas

Reputation: 145755

You have some issues:

  1. Typo, you use appp$UB_T in the range(), which doesn't exist. You need ap_pp$UB_T
  2. Range. The line data you are trying to plot has a minimum of 0.05:
range(ap_pp$appp)
[1] 0.05342565 1.79114872

However, you set the y-axis to have a maximum of 0.02:

range(c(ap_pp$LB_T, ap_pp$UB_T))
[1] -0.003995396  0.021642933

Since the maximum of your y axis, 0.0216, is less than the minimum of the data you are plotting, 0.0534, all the points you are trying to plot are "above" the graph.

  1. Graph type. You say "line", but by default plot will plot points. If you want a line, use type = "l". (Or lines(), as you do later.)

  2. I have no idea what xx is, so I don't know what's going on with your polygon code. But presumably the y limits are again defined by UB_T and LB_T, and so the maximum of the y axis is still lower than the minimum of the data in lines()

  3. Duplicate column names are a bad idea. You have two columns named LB_T and two named UB_T. They appear to be identical, which is less bad than if they were different, but I would strongly suggest not using duplicate column names so there is no ambiguity about which column you are referring to.

Perhaps you should include ap_pp$ppp in the range call.

Upvotes: 1

Related Questions