0

I am trying to conduct a RDA analysis, and to do so I had to create a plot with my SNPs (the points on the scatterplot). I assigned colours to my points, but once I plotted them, they were not filled and instead were white circles outlined in gray. Attached is my code, and attached is the image of what I got, and an image of what I want it to look like. Also attached is an image of a smaller dataset to make it easier to see what I'm doing! Thank you in advance!

#gen1 Dataset
 POP   L0001 L0002 L0003
   <chr> <dbl> <dbl> <dbl>
 1 AK        0     1     0
 2 NU       -1    -1    -1
 3 GR        1     0     0
 4 LB        0     1     0
 5 NF        1     0     0
 6 ST        0     0     0
 7 NS       -1     2     0
 8 NB        1     2     0
 9 ME        0     1     0
10 IC        0     0     0
11 FI        0     0     0

#env1 dataset
POP   CHLa.max CHLa.min CHLa.avg
   <chr>    <dbl>    <dbl>    <dbl>
 1 AK       2.07    0.0623    0.780
 2 NU       0.943   0.0697    0.245
 3 GR       2.03    0.0494    0.453
 4 LB       1.55    0.263     0.678
 5 NF       1.63    0.190     0.698
 6 ST       2.40    1.17      1.74 
 7 NS       1.14    0.0708    0.447
 8 NB       1.79    0.231     0.900
 9 ME       1.69    0.131     0.711
10 IC       2.28    0.147     0.892
11 FI       0.554   0.0569    0.207

#Specify columns
gen1<-gen1[2:4]

#Specify predictors
pred1<-subset(env1[,1])

#Conduct RDA
BLGU.rda <- rda(gen1 ~ ., data=pred1, scale=T)
BLGU.rda

#Define Populations
levels(env1[["POP"]]) <- c("AK", "NU", "GR", "LB", "NF", "ST", "NS", "NB", "ME", "IC", "FI")

#Give Populations Callback Name
eco1 <- env1[["POP"]]

#Assign Colours
bg <- c("#fa8a6b", "#5d7142", "#010c22", "#61cd9e", "#7110b6", "#15c4df", "#892f74", "#0615f3", "#b6faea", "#e402b1", "#ad4833")

#Plot RDA
plot(BLGU.rda, type="n", scaling=2)

#Plot populations
points(BLGU.rda, display="sites", pch=21, cex=1.3, col="gray32", scaling=2, bg=bg[eco])

env1 Data

gen1 Data

Scatter Plot of RDA (SNPs vs Environmental Predictors

Scatter Plot of what I want my data to look like

Bryan
  • 2,870
  • 24
  • 39
  • 44
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 13 '20 at 16:24
  • A reproducible example may be difficult (There are 3000 points and I'm not sure which ones are the "outliers" so I can't exactly narrow them down to plot them), but I can reduce the amount of code to the necessary components so it's easy to plot if that helps - see the updated code above if it's easier for you to work with. Regardless, thank you! – Daniel.Payter Feb 13 '20 at 16:32
  • We don't need your real data. Maybe make a fake data set with 20 points that we can use for testing. It's really not clear how `BLGU.rda` relates to `env`. – MrFlick Feb 13 '20 at 16:35
  • I just updated the question to have a far smaller dataset, and I included pictures as to what the dataset looks like! – Daniel.Payter Feb 13 '20 at 18:45
  • Pictures of data are pretty impossible to run code on. Please share the data in a copy/pasteable way---`dput()` makes this easy, running `dput(env1)` gives a copy/pasteable version of `env1`, or use `dput(env1[1:10, ])` for just the first 10 rows. See the link in MrFlick's first comment for more explanation and advice like that. – Gregor Thomas Feb 13 '20 at 18:59
  • Thanks for the tip! I just posted a table in the question. – Daniel.Payter Feb 13 '20 at 19:05

1 Answers1

0

What you want to do is to plot the data points on the rda, and color them according to one column, if I understood you correctly.

Your data (which takes a while to read in):

env1 <- structure(list(POP = structure(c(1L, 10L, 3L, 5L, 8L, 11L, 9L, 
7L, 6L, 4L, 2L), .Label = c("AK", "FI", "GR", "IC", "LB", "ME", 
"NB", "NF", "NS", "NU", "ST"), class = "factor"), CHLa.max = c(2.07, 
0.943, 2.03, 1.55, 1.63, 2.4, 1.14, 1.79, 1.69, 2.28, 0.554), 
    CHLa.min = c(0.0623, 0.0697, 0.0494, 0.263, 0.19, 1.17, 0.0708, 
    0.231, 0.131, 0.147, 0.0569), CHLa.avg = c(0.78, 0.245, 0.453, 
    0.678, 0.698, 1.74, 0.447, 0.9, 0.711, 0.892, 0.207)), class = "data.frame", row.names = c(NA, 
-11L))

gen1 <- structure(list(POP = structure(c(1L, 10L, 3L, 5L, 8L, 11L, 9L, 
7L, 6L, 4L, 2L), .Label = c("AK", "FI", "GR", "IC", "LB", "ME", 
"NB", "NF", "NS", "NU", "ST"), class = "factor"), L0001 = c(0L, 
-1L, 1L, 0L, 1L, 0L, -1L, 1L, 0L, 0L, 0L), L0002 = c(1L, -1L, 
0L, 1L, 0L, 0L, 2L, 2L, 1L, 0L, 0L), L0003 = c(0L, -1L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA, 
-11L))

The rda steps and plot, please include libraries next time:

library(vegen)
BLGU.rda <- rda(gen1[,-1] ~ as.matrix(env1[,-1]), scale=T)

#Assign Colours
bg <- c("#fa8a6b", "#5d7142", "#010c22", "#61cd9e", "#7110b6", "#15c4df", "#892f74", "#0615f3", "#b6faea", "#e402b1", "#ad4833")
names(bg) <- c("AK", "NU", "GR", "LB", "NF", "ST", "NS", "NB", "ME", "IC", "FI")

plot(BLGU.rda, type="n", scaling=2)
points(BLGU.rda, display="sites", pch=21, cex=1.3, col="gray32", scaling=2, bg=bg[as.character(env1$POP)])
legend("topright",fill=bg,names(bg),ncol=3)

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72