1

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?

camdenl
  • 1,065
  • 2
  • 19
  • 31
  • Can you please post a [minimal, reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). None of the variables in your `ggplot` call are represented in your sample data. Thanks. – Henrik Dec 05 '13 at 20:09
  • Edited plot call to reflect variable names – camdenl Dec 05 '13 at 20:20

1 Answers1

4

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

Sven Hohenstein
  • 78,180
  • 16
  • 134
  • 160