plot error x y length difference
2
0
Entering edit mode
5.3 years ago
yusuf ▴ 70

I have used this command

plot(log.norm.counts.a[,1:2], cex=.1)

but it gives following error

Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ

I can't make changes in the file.

anyone know how to solve, like skip ids which are missing.

RNA-Seq ggplot • 4.0k views
ADD COMMENT
1
Entering edit mode

You can make changes in the object you create by reading the file. Please search Stack Overflow to understand how to manipulate data frames.

ADD REPLY
1
Entering edit mode

Can you show us a subset of your dataframe ?

The error message say that you do not have the same length between log.norm.counts.a[,1] and log.norm.counts.a[,2]. Have you tried to check the content of these two columns ?

ADD REPLY
6
Entering edit mode
5.3 years ago
kashiff007 ★ 1.9k

Try this code. It should solve your problem

data <- read.csv("~/Desktop/my_data.csv", header=TRUE)
dim(data)
rnames <- data[,1]                            # assign labels in column 1 to "rnames"
mat_data <- data.matrix(data[,2:ncol(data)])  # transform column 2-5 into a matrix
rownames(mat_data) <- rnames        
mat_data         # this is only matrix now with dimension n rows and 12 column
x1 <- mat_data[,1:6]  # assigning first 6 cols to x1
y1 <- mat_data[,7:12]  # assigning seventh to 12 cols to x1

install.packages("matrixStats")
library(matrixStats)
x2 <- rowSds(x1)     # standard deviation from x1
y2 <- rowSds(y1)    #  standard deviation from y1


plot(x2,y2) # for plot
ADD COMMENT
1
Entering edit mode

it worked

thanks :)

ADD REPLY
2
Entering edit mode

If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they all work.

Upvote|Bookmark|Accept

ADD REPLY
0
Entering edit mode
5.3 years ago
yusuf ▴ 70

Hi thankyou for your reply

I want to plot SD of two groups of files, with different length

I have slightly solved this by

Y2 <- as.data.table((log.norm.counts.a[,1:6]), keep.rownames = "geneid")
X2 <- as.data.table((log.norm.counts.b[,1:6]), keep.rownames = "geneid")
m3 <- merge(X2,Y2,by=c("geneid"))
head(m3)

dim(m3)
[1] 1500    13


X1 <- m3[,2:7]
head(X1[,1:6])
Y1 <- m3[,8:13]
head(Y1)

but when i try

a<- as.data.table(rowSds(X1))
b<- as.data.table(rowSds(Y1))
plot(a,b)

or

plot(rowSds(m3[,2:7]),rowSds(m3[,8:13]))

it gives error

Error in rowVars(x, rows = rows, cols = cols, na.rm = na.rm, center = center,  : 
  Argument 'x' must be a matrix or a vector.

even

class(m3)
[1] "matrix"
ADD COMMENT
1
Entering edit mode

Have you checked the first few lines of "m3" matrix. what is your head(m3) output?

ADD REPLY
0
Entering edit mode

yes

> head(m3)

           geneid FP13w0L.x FP20w0L.x FP27w0L.x FP39w0R.x FP46w0R.x FP7w0L.x FP13w0L.y    
1: ENSG00000000003  5.832952  5.702980  5.890075  5.429769  6.197564 5.405774  6.093247    
2: ENSG00000000005  0.000000  4.092157  2.959349  2.626327  1.978803 2.133864  0.000000
3: ENSG00000000419  8.154151  7.716715  8.377897  8.100886  8.392561 8.289250  8.287379



   FP20w0L.y FP27w0L.y FP39w0R.y FP46w0R.y FP7w0L.y
1:  5.894538  6.105176  5.741960  6.249536 5.527603
2:  4.297580  3.116547  2.726263  2.077238 2.933729
3:  7.738360  8.420916  8.152382  8.435377 8.327208
ADD REPLY
1
Entering edit mode

Can you try to do class(m3[,2:7]) ? sometimes the class of the object changes when you subset it.

If this is the case, then a solution to your problem would be plot(rowSds(as.matrix(m3[,2:7])), rowSds(as.matrix(m3[,8:13])))

ADD REPLY
0
Entering edit mode

yup tried didn't work,

but made the matrix again and it worked.

ADD REPLY
1
Entering edit mode

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.
code_formatting

Also, please do not use # in front of plain text content. If they're code comments, the entire content should be formatted as code.

ADD REPLY

Login before adding your answer.

Traffic: 1792 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6