Heatmap
0
0
Entering edit mode
17 months ago

Hi,

I´m trying to do a heatmap with ggplot but when I´m going to represent my values (Excel) and I write the command:

data_heatmap <- expand.grid(X=x, Y=y)
head(data_heatmap)

data_heatmap$Z<- runif(21, -3, 3)
View(data_heatmap)

ggplot(data_heatmap, aes(X, Y, fill= Z)) + 
  geom_tile() +
  scale_fill_gradientn(colors = c("red", "white", "blue")) 

The values that R reads are different

How can I import de desired values?

Thanks.

Log2FoldChange Heatmap • 803 views
ADD COMMENT
1
Entering edit mode

Coincidentally, I have quite recently posted an example how to create a heatmap with ggplot2. Like your code, which will also produce a simple heatmap, both examples make use of randomly generated sample data (e.g. with runif(21, -3, 3)).

To get your own data from Excel into the heatmap, you will need to export it to a csv/tsv file and read this file into R. There are several functions to do so, read.delim() is one of them. However, I think you might need to brush up on the fundamentals first, before you proceed. Run above script line by line, see what it does and then start modifying the values.

Using ChatGPT is also very helpful here, because you can paste above code into the prompt and ask it to explain said code. Since you can have a dialogue about each step, you can also ask differently about what you have not yet understood!

ADD REPLY
0
Entering edit mode

Thank you, it worked.

ADD REPLY
0
Entering edit mode

What are you trying to do? It's not clear at all.

ADD REPLY

Login before adding your answer.

Traffic: 1640 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