Entering edit mode
17 months ago
smanzano250800
•
0
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.
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!
Thank you, it worked.
What are you trying to do? It's not clear at all.