how to draw group membership probabilities into scatter plots

I have csv file having 4 columns 1st clum is members and remaining columns are their group membership probabilities. Now i would like to create scatter plot like in the attached file, is it possible with ggplot2 in R? any help in this regard will be highly appreciated.
Thanks in advance

group membership

How was the plot you shared made?

Here is a simple example of a similar plot. What determines the x and y positions on your plot?

#Invent data
DF <- data.frame(Group = c("A","A","A","B","B","B","C","C","C"),
                 X = c(0.13,0.23,0.27,0.55,0.52,0.43,0.71,0.74,0.65),
                 Y = c(0.32,0.3,0.22,0.44,0.40,0.53,0.75,0.68,0.7))
#Calculate group means
DF <- DF |> group_by(Group) |> 
  mutate(GrpMeanX = mean(X), GrpMeanY = mean(Y))

DFmeans <- DF |> group_by(Group) |> summarize(MeanX = mean(X), MeanY = mean(Y))

ggplot(DF) +
  geom_segment(aes(x = X, y = Y, xend = GrpMeanX, yend = GrpMeanY, color = Group)) + 
  geom_point(aes(x = X, y = Y, color = Group)) + 
  geom_label(aes(x = MeanX, y = MeanY, label = Group), data = DFmeans)

1 Like

Hi dromano
Thanks for your message. I can create example shown graph using this code

grp<-find.clusters(gen,max.n.clust = 10) 
dapc1<-dapc(gen,grp$grp) # up to here i have data shown as in my example
scatter(dapc1) # here i want to plot the clusters using dataframe.

i have individuals with membership probabilities not exactly as groups i need to group them based on similar membership probabilities. I hope i explained you well.

Thanks for your help to my request. Your code is working good, but i have individuals with membership probabilities not exactly as groups i need to group them based on similar membership probabilities of groups from Q1 to Q3, other than this your code working well.

Could you describe or share the contents of x1? To share them, you could execute the following lines:

sink("x1.txt")       # directs output to a new file called "x1.txt"
dput(x1[1:20, 1:20]) # writes code for recreating a few rows and columns of x1  to "x1.txt"
sink()               # restores output back to the console

and then

  • open the file "x1.txt" and copy the output
  • paste the output here, between a pair of triple backticks like this:
[<-- paste here]

This topic was automatically closed 42 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.