Plot with labels on the x axis

r

Solution

Because your x variable is discrete, you need to do this a little differently:

plot(seq_along(x),intensity,type = "l",axes = FALSE)
axis(side = 2)
axis(side = 1,at = seq_along(x),labels = x)

The idea being that you create the plot with numerical values for the x axis, and then simply add your particular labels.

You can add a call to `box()` if you miss the full box around the plot.

Problem

I want to have a straight line plot of intensity values for 10 different molecules with molecule name on the x axis and intensity value on the y axis. I tried: ``` x = c("Mol 1","Mol 2","Mol 3","Mol 4","Mol 5","Mol 6","Mol 7","Mol 8","Mol 9","Mol 10") intensity = c(428,409,388,378,373,140,137,138,139,144) plot(x,intensity) ``` But it returned this error message? Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf

Original source