'R plot graph for data coordinates not showing up

I have a set of data coordinates I'm trying to show on Rstudio.The issue starts when I try to run the plot function for a dataframe since that format does not show anything on the plot.

Here is the running code

{
alph=5
alphSeq1<-round(rand(1,alph),1)*10
alphSeq2<-round(rand(1,alph),1)*10
 
 alph_df<-data.frame(alphSeq1,alphSeq2)
 
 par(mar=c(1, 1, 1, 1))

 #plot(alphSeq1, alphSeq2,cex = 1, pch = 3,type="p", xlab = "Var 1", ylab = "Var 2")
 
plot(alph_df$alphSeq1, alph_df$alphSeq2,type="p", xlab = "Var 1",  
ylab = "Var2",xlim=c(0,10),ylim=c(0,10))
}

Has anyone else run into this? I would really like to clarify on here in case.



Solution 1:[1]

These modifications in your code will produce the plot. The problem was that the rand() function returns a one-row, five column matrix. When you combine them in data.frame() it creates a one-row, ten column matrix. Converting them to vectors creates a two column, five row data frame:

library(pracma)
{
alph=5
set.seed(42)
alphSeq1<-as.vector(round(rand(1,alph),1)*10)
alphSeq2<-as.vector(round(rand(1,alph),1)*10)

par(mar=c(1, 1, 1, 1))
plot(alph_df$alphSeq1, alph_df$alphSeq2,type="p", xlab = "Var 1",  
ylab = "Var2",xlim=c(0,10),ylim=c(0,10))
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dcarlson