Trying to plot multiple curves on one graph using ggplot2. The x-axis will be wavelength, the y-axis will show intensity.
Data Table (called ‘Set’) is shown below (col2 refers to column 2 etc.), wavelength goes from 3600 to 8000 wavenumbers. Each of col1, 2, 3 all have different values, leading to different curves. The columns provide values in intensity.
Wavelength col1 col2 col3
The melt syntax can be found below, at melted.
df<-data.table(Set)
melted <- melt(df, id.vars = NULL, measure.vars=colnames(df),
variable.name = "wavelength", value.name = "value")
wavelength value
1: Wavelength 3600.809
2: Wavelength 3601.637
etc
To plot,
ggplot(
plot_input[wavelength %in% c("col1", "col2", "col3”)],
aes(y=value, x=wavelength)) +
geom_line() +
theme_classic()
Issues –
2 ggplot output [per image] results in three vertical lines, am trying to plot three distinct curves for each of col1, col2, col3
2 ggplot – looking for wavenumbers on the x-axis, not col_num
I am probably missing something very simple. Could someone explain what I am doing incorrectly?
Thank you.
[additional image added, apols for poor quality]. Shown are 5 spectra, in colours. The data is contained in the columns - y values]