jaganathan mk
jaganathan mk

Reputation: 1

Heatmap for the trajectory data in R

I have (x,y) data in a text file (data.csv) I would like to make into a heat map in R like this https://www.youtube.com/watch?v=cFGu3O30a3wenter image description here

Upvotes: 0

Views: 286

Answers (2)

Surak of Vulcan
Surak of Vulcan

Reputation: 434

You can also create a 2D histogram, like that:

library(gplots)

# number of bins in both dimensions
resolution <- 50

# toy data (sorry about copying from jyjek)
df <- data.frame(x=sample(resolution,5000,replace = T),
           y=sample(resolution,5000,replace = T))

# the shown example has "jet" palette
jet.colors <-
  c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")

# the example has no margins           
par(mar=c(0,0,0,0))         

# plot the histogram without axes
hist2d(df, nbins=resolution, xaxt="n", yaxt="n", col=jet.colors)

Upvotes: 0

jyjek
jyjek

Reputation: 2707

Something like that?

library(tidyverse)
library(echarts4r)
df<-data.frame(x=sample(50,5000,replace = T),
               y=sample(50,5000,replace = T))

df%>%
  count(x,y)%>%
  e_chart(x)%>%
  e_heatmap(y,n) %>% 
  e_visual_map(n)%>%
  e_title("Heatmap")

Upvotes: 2

Related Questions