0

This is my first post on stackoverflow - this site has saved me many long futile efforts down impossible roads, thank you all for your time!

I'm trying to graph presence/absence phenology data for a plant species with Date on the x-axis and Distance (in km) on the y-axis. I've tried scatterplot(), ggplot(), plot()....I'm pretty new to R and i'm running out of ideas - especially how to communicate to the function which column to treat as x, which as y, and which contains the presence/absence data to be plotted with a dot/x/etc. My data is column stacked - col1 = Date, col3 = river km, and col4 = 0/1 data

I'm sorry, I would post my data, but I can't seem to format it correctly for this site. I'd really appreciate any hints.

Erick

Update:

Date        Transect  river.km  TARA
2014-03-13    ST1-1     2.172     0
2014-03-21    ST1-1     2.172     0
2014-03-13    ST1-2     8.450     1
2014-03-21    ST1-2     8.450     1
2014-03-13    ST1-3     16.27     0
2014-03-21    ST1-3     16.27     1  

My best thought as to coding would be:

scatterplot(river.km~Date, data=TARA)    

but obviously, that doesn't work. Thanks for taking a look.

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • 1
    You should take the time to create a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (read that question for tips on sharing some sample data). Show the code you've tried and describe exactly how it didn't match what you desired. – MrFlick Jan 19 '15 at 22:34
  • Use the code button (looks like this {}) to format code and data. – bsg Jan 19 '15 at 22:56
  • `dput()` will help you to format a chunk of your data to share here. – Steven Jan 20 '15 at 03:53

1 Answers1

1

I recommend using the ggplot2 package for this. If I understand correctly you want to map Date to position on the x-axis, river.km to position on the y-axis, and TARA to shape. You can do that in ggplot as follows:

tmp <- read.table(text = "Date        Transect  river.km  TARA
2014-03-13    ST1-1     2.172     0
2014-03-21    ST1-1     2.172     0
2014-03-13    ST1-2     8.450     1
2014-03-21    ST1-2     8.450     1
2014-03-13    ST1-3     16.27     0
2014-03-21    ST1-3     16.27     1",
                  header=TRUE,
                  colClasses = c("Date", "character", "numeric", "character"))

library(ggplot2)
ggplot(tmp, aes(x = Date, y = river.km, shape = TARA)) +
  geom_point()

enter image description here

Ista
  • 10,139
  • 2
  • 37
  • 38
  • it might be nice to use open and closed symbols (e.g. `scale_shape_manual(values=c(1,16))` to denote absent and present respectively. – Ben Bolker Jan 20 '15 at 15:06
  • Thank you everybody. I'm still having some difficulty: Error message reads : "Error in aes(x = Date, y = river.km, shape = TARA) + geom_point() non-numeric argument to binary operator" Based on this code: `taraData<-read.csv("taraPresence.csv",header=TRUE,colClasses=c("Date", "character", "numeric", "character")) attach(taraData) library(ggplot2) ggplot(taraData, aes(x = Date, y = river.km, shape = TARA)+geom_point())` – Erick Lundgren Jan 22 '15 at 18:20
  • You want `ggplot(taraData, aes(x = Date, y = river.km, shape = TARA))+geom_point()` rather than `ggplot(taraData, aes(x = Date, y = river.km, shape = TARA)+geom_point())`. – Ista Jan 22 '15 at 19:01