user888
user888

Reputation: 13

How to solve R linear regression graph problem?

I have a problem with the following graph:

graph

For every value that I put in plot() I get this graph. Does anyone maybe know what it means?

Cor.test works, I got weak correlation.

my code:

cor.test(podatki$v54, podatki$v197, method = c("pearson"), 
         conf.level = 0.95, use = "all.obs" )


plot(podatki$v54, podatki$v197)

Upvotes: 1

Views: 54

Answers (1)

bstrain
bstrain

Reputation: 278

Your graph looks that way because the points are plotted directly on top of one another.

You can use the jitter(...) function to add small amounts of randomness to the data points so they aren't directly on top of one another (it jitters them around so you can see the ones underneath!) Here is an example you can copy and paste:

# create some random numbers to plot. all are values 1-5.    
x1 <- sample(c(1:5), 100, replace = TRUE)
x2 <- sample(c(1:5), 100, replace = TRUE)

# plotting without jitter
plot(x1, x2)

enter image description here

# plotting with jitter 

plot(jitter(x1), jitter(x2))

enter image description here

jitter(...) changes the values by small amounts so only use the jittered data for plotting, otherwise it will bias your results!

Upvotes: 1

Related Questions