-1

I have five sets of data that I need on one plot. I need the x-axis to be lidar and the y-axis to be FPC.

I am using ggplot2. So far I have the following code:

setwd("C:/r/LIDAR_FPC")

AllLidarvsFPC.df <- data.frame(read.csv("AllLidarvsFPC.csv"))
AllLidarvsFPC = read.csv("AllLidarvsFPC.csv", header=TRUE)

library(ggplot2)

p <- ggplot(AllLidarvsFPC.df, aes(AllLidarvsFPC.df[,1], AllLidarvsFPC.df[,2])) + 
     geom_point() + 
     scale_x_continuous(limits=c(-30,100), breaks=c(-30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)) + 
     scale_y_continuous(limits=c(-10,120), breaks=c(-10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100))`

p + 
labs(y = "2013 Percentage cover (%) derived from LiDAR") + 
labs(x = "2013 FPC (%) derived from Landsat") + 
stat_smooth(method = "lm", formula = y ~ poly(x, 5), size = 0.5, col="black")

However, this only plots the first set of data: WildmanFPC. I need all the FPC data sets plotted!

enter image description here

Emma
  • 11
  • Hi, you would have to add a reproducible code..otherwise it will be too difficult to reproduce your problem on our machines and solve..read here how to do so.. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Dhawal Kapil Feb 17 '16 at 23:51
  • also see this line `aes(AllLidarvsFPC.df[,1], AllLidarvsFPC.df[,2])) ` you are plotting x vs y only which is i think WildmanFPC – Dhawal Kapil Feb 17 '16 at 23:52
  • see this also how to convert your data to long form and then plot http://stackoverflow.com/questions/17150183/r-plot-multiple-lines-in-one-graph – Dhawal Kapil Feb 17 '16 at 23:55
  • With out reproducible code I'm not sure if this will work. Use `melt` to create a long table were the variable will be your colnames, value will be your values stacked. Then a simple colouring can help `P<- ggplot(AllLidarvsFPC.df, aes(x = LIDAR, y= value, color= variable)) + geom_point()` – George Feb 18 '16 at 01:03

1 Answers1

1

Since there is no working data to use, I have made a sample data frame to show you how to apply it to your code. In the future it is best to provide reproducible code, that way it speeds up responses.

library(ggplot2)
library(reshape2)

df <- data.frame(LIDAR=c(1,2,3,4), WildmanFPC=c(3,5,2,6), WestAlligatorFPC=c(5,6,7,12), SouthAlligator=c(12,7,1,0))
df_melt<-melt(df, id.vars = 'LIDAR')

ggplot(df_melt, aes(x=LIDAR, y = value, color= variable))+ geom_point()

enter image description here

George
  • 903
  • 8
  • 22