1

I'm trying to plot three accumulation curves in one plot only. I proceed the command to create df as follows:

df1 <- data.frame(sac1$richness,sac1$sites,sac1$sd)    df2 <-     
data.frame(sac2$richness,sac2$sites,sac2$sd)    df3 <- 
data.frame(sac3$richness,sac3$sites,sac3$sd)

I can plot each one separated in ggplot2 and it runs ok. But I have no way to put all curves together in one plot only. Do ggplot2 do that?

T have tried melt dfs, add=T and other things. Nothing worked. I've seen the GGPLOT2 book, but I did not find accumulation curves in there.

dwitvliet
  • 7,242
  • 7
  • 36
  • 62
user3830965
  • 11
  • 1
  • 2
  • It's hard to provide specific suggestions when you didn't supply any sample data or the code you used to make one plot. If we can't recreate what you see, it is very difficult to help you. See [how to make a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for tips to improve your question. You should, in theory, either be able to merge/melt your data.frames or use separate `data=` parameters to your `ggplot` layers. – MrFlick Jul 11 '14 at 22:53

1 Answers1

1

Read in your data

df1 <- data.frame(sac1$richness,sac1$sites,sac1$sd)
df2 <- data.frame(sac2$richness,sac2$sites,sac2$sd)
df3 <- data.frame(sac3$richness,sac3$sites,sac3$sd)

Make sure all colnames are the same

colnames(df1) <- c("richness","sites","sd","type") 
colnames(df2) <- c("richness","sites","sd","type")
colnames(df3) <- c("richness","sites","sd","type")

Add new column to each df as an identifier

df1$type <- "sac1"  
df2$type <- "sac2"  
df3$type <- "sac3"    

rbind everything together

df <- rbind(df1,df2,df3)

I've never done a species accumulation curve, but I imagine it would look like this

ggplot(df, aes(x=sites, y=richness)+
  facet_wrap(~type)+
  geom_point()

Though it's hard to say for sure without a reproducible example

Sardimus
  • 156
  • 8