Point shape in ggplot2 with distance matrix

Hello Rstudio community,
I have just a little problem when I create a PCoA representation with ggplot2 (representation joint) . I used a matrix distances (with Bray Curtis) but I need a shape differentiation by size in my samples ( 0.2 and 3) in addition with the differentiation by color for origin sample (need four colors Laz, Mis, QN, Sur). Do you think there are a solution for these in ggplot2 with a matrix distances ?
Thank you for your help :slight_smile:

39

Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

Sorry , I ask some help on R community for the first time.
May be with the code like these it's better :

#Load library
library("ggplot2")
library("scales")
library("grid")
library("reshape2")
library("plotly")
library("reshape2")
library("vegan")
library("vegetarian")
library("factoextra")
library("HH")
library("usdm")
library("stats")
library("ggfortify")
library("cluster")
library("ecodist")

#Make a csv table very simple, with letter instead of name in row and columns 
data("iris")
#import data
datamatrix<-distance(iris[, 1:4], "bray-curtis")

#Check data
#View(datamatrix)
#Bray-curtis distance
dist <- distance(datamatrix, method="bray-curtis")
matrixdist <- as.matrix(dist)

#Use a distance matrix for applicate this code 
#Charger la librairie nécessaire
library("ggplot2")
library("scales")
library("grid")
library("reshape2")
library("plotly")
library("reshape2")


pcoA<-read.table(file="matrixbc.txt", header=T, sep="\t", dec=",")
#pcoA

palette=c("#99cc00", "#33ff33", "#ffcc00","#ffff00","#ff33cc","#ff3399","#ff3300","#990000")
names(pcoA)[2:3] <- c('pcoA1', 'pcoA2')

ggplot(pcoA, aes(x=pcoA1 , y = pcoA2), shape= size) + #but where I have my problem
  theme_bw() +
  geom_point(aes(colour=1), size =3, pch=19) +
  scale_colour_manual('Species',values=palette)

Sorry but your code is not actually reproducible since we don't have access to "matrixbc.txt" file, and it's not pretty clear what you want to achieve, could you elaborate a little more in your question? Also, please narrow down your code to just the relevant section (only include the libraries relevant to your issue).

Maybe this FAQ would give you a better idea of how to make a proper reprex

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.