This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Help with R studio

Does anyone know what is wrong with this? it has worked in the past. Also, how do I ensure that all of the graph fits on the pdf export? It cuts off.

pheatmap(log2(data + 1), cluster_rows=T, cluster_cols=F, show_rownames = T, cellwidth = 7)
Error in Math.data.frame(data + 1) : 
  non-numeric variable in data frame: c(NA, NA, NA, NA, NA)
In addition: Warning message:
In Ops.factor(left, right) : ‘+’ not meaningful for factors

Thanks Em

r

I added code markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

Something is wrong with your data variable - it's not what you think it is. Have a look at it using str(data) and head(data).

Hello,

It's what I expect it to be and have used before - a list of genes and the coinciding gene expression number - should I format the cell in a certain way?

Thanks!

Can you post str(data)? The warning says there are unexpected factors. Make sure the data types of your variables and columns are correct.

These are the first few lines:

'data.frame':   5 obs. of  1405 variables:
 $ X                                : Factor w/ 5 levels "AMBRA1","BNIP3",..: 1 2 3 4 5
 $ E3.1.443.fastq.counts.txt        : int  605 649 174 96 43
 $ E3.1.444.fastq.counts.txt        : int  256 309 96 54 42
 $ E3.1.445.fastq.counts.txt        : int  1004 1209 734 149 121
 $ E3.1.447.fastq.counts.txt        : int  324 377 304 75 90
 $ E3.1.448.fastq.counts.txt        : int  115 144 253 99 34
 $ E3.2.449.fastq.counts.txt        : int  522 92 587 191 188
 $ E3.2.450.fastq.counts.txt        : int  428 231 425 90 74
 $ E3.2.452.fastq.counts.txt        : int  1202 1152 475 33 507

AGAIN: I added code markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

And look at the column with name X. That's a factor. You cannot do a factor + 1.

The cell on the .csv with the X is blank - how do I resolve the issue?

According to the output of str() it's not blank. It at least contains 5 levels "AMBRA1","BNIP3". You can drop the column from data.

To complement this, check how you're reading the data. The read.table() function and it's variants read a column of numbers as strings and convert them to factors if they see anything that doesn't look like numbers (like NA for example). Also since R 3.1, numbers with too many digits are also read as strings and converted to factors. See type.convert().

Hello!

this is how I am currently reading the .csv:

data <- read.csv("Main Mitophagy Genes.csv") #open count file as data variable
data <- read.csv("Main of Mitophagy Genes.csv", header=T, row.names=1, check.names=F) #make it readable

Thanks Emma

AGAIN AGAIN

I added code markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

If you want help - spend some effort making your question easy to read.

Do you mean you're reading it twice ? Or that these are the two different commands that you've tried ?

1 answer

data+1 will try to add 1 to everything, e.g. including the gene names which are not numeric. The solution is to select only the numeric rows/columns before doing numerical operations. It looks like your gene names are in the first column so data[,-1]+1 should work.

Log in to answer this question.