-3

I've got a dataset of different energies (eV) and related counts. I changed the detection wavelength throughout the measurement which resulted in having a first column with all wavelength and than further columns. There the different rows are filled with NAs because no data was measured at the specific wavelength. I would like to plot the spectra in R, but it doesn't work because the length of X and y values differs for each column.

It would be great, if someone could help me.

Thank you very much.

  • 1
    Please create a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), so that we can get an idea what your data looks like, what your expected output is and what you've tried. – emilliman5 Mar 01 '17 at 20:29

1 Answers1

0

It would be better if we could work with (simulated) data you provided. Here's my attempt at trying to visualize your problem the way I see it.

library(ggplot2)
library(tidyr)

# create and fudge the data
xy <- data.frame(measurement = 1:20, red = rnorm(20), green = rnorm(20, mean = 10), uv = NA)
xy[16:20, "green"] <- NA
xy[16:20, "uv"] <- rnorm(5, mean = -3)

# flow it into "long"  format
xy <- gather(xy, key = color, value = value, - measurement)

# plot
ggplot(xy, aes(x = measurement, y = value, group = color)) +
  theme_bw() +
  geom_line()

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197