1

I want to create a simple scatterplot using a table with 2 variables. The Table looks like this:

> freqs
      Var1 Freq
1        1  200
2        2   50
3        3   20  

I got it using freqs <- as.data.frame(table(data$V2)) to compute the frequency of numbers in another table.

What I do right now is:

plot(freqs, log="xy", main="Frequency of frequencies",
xlab="frequencies", ylab="frequency of frequencies")

The problem is, that I get a plot with lines, not dots, and I don't know why. For another list plot() behaved differently and used dots. It looks like this:

I know that plot depends on the datatype that it gets. So is the problem in the way I generate freqs?

Edit:

Here is the data as requested: link

Steps were:

data <- read.csv(file="out-kant.txt",head=FALSE,sep="\t")
freqs <- as.data.frame(table(data$V2))
plot(freqs,log="xy",main="Frequency of frequencies", xlab="frequencies", ylab="frequency of frequencies") 
albert
  • 8,285
  • 3
  • 19
  • 32
  • 1
    can you provide more information so others can reproduce this please. Such as the data used. – zacdav Nov 02 '15 at 13:25

1 Answers1

2

It seems like the type of one of your variables is not set as an integer. You get a scatterplot when both x and y are integers. For example, when you run this code you will get a scatterplot, because it automatically sets both variables as integers:

freqs <- read.table(header=TRUE, text='Var1 freq
               1  200
               2  50
               3  20')

plot(freqs, log="xy", main="Frequency of frequencies", xlab="frequencies", ylab="frequency of frequencies")

enter image description here

Check what type your variables are with:

typeof(freqs$freq)
typeof(freqs$Var1)

Then, if it is not an integer, fix it with:

freqs$freq <- as.integer(freqs$freq)
freqs$Var1 <- as.integer(freqs$Var1)

EDIT: So I managed to reproduce your issue when I ran:

freqs$Var1 <- as.factor(freqs$Var1)
plot(freqs, log="xy", main="Frequency of frequencies", xlab="frequencies", ylab="frequency of frequencies")

enter image description here

Perhaps your Var1 variable is specified as a factor. Try running:

freqs$Var1 <- as.numeric(freqs$Var1)

EDIT2: Used the above code to make freqs$Var1 numeric on the data provided on the main question's edit, which fixed the issue.

kneijenhuijs
  • 1,189
  • 1
  • 12
  • 21