1
votes

I have a dataframe of reflectance data that I have melted to more easily use ggplot, here's the first few rows of the dataframe bronmelt:

   variety  wavelength   reflectance
1 magnolia  wavel.400    1.602868
2 carlos    wavel.450    1.778760
3 scupper   wavel.500    1.352016
4 magnolia  wavel.600    5.969302
5 scupper   wavel.900    1.491008

My problem is that when I call a simple plot:

ggplot(data=bronmelt, aes(x=wavelength, y=reflectance, color = variety)) + geom_point()

to plot the data, I can't get the x axis to be seen as a continuous variable.

How do I create a custom x axis from 400-900 that has tick marks every 20 points?

1
Can you please post a minimal, reproducible example. None of the variables in your ggplot call are represented in your sample data. Thanks.Henrik
Edited plot call to reflect variable namescamdenl

1 Answers

4
votes

First create a new column with numeric wavelengh values:

bronmelt <- transform(bronmelt, 
                      wavelength2 = as.integer(substr(wavelength, 7, 10)))

The plot:

library(ggplot2)
ggplot(data=bronmelt, aes(x=wavelength2, y=reflectance, color = variety)) + 
  geom_point() +
  scale_x_continuous(breaks = seq(400, 900, 20))

The last line specifies the axis breaks ranging from 400 to 900 in steps of 20.

enter image description here